1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tatyana61 [14]
2 years ago
9

3-Write a program in some language that has both static and stack dynamic local variables in subprograms. Create six large (at l

east 100 * 100) matrices in the subprogram—three static and three stack dynamic. Fill two of the static matrices and two of the stack-dynamic matrices with random numbers in the range of 1 to 100. The code in the subprogram must perform a large number of matrix multiplication operations on the static matrices and time the process. Then it must repeat this with the stack-dynamic matrices. Compare and explain the results. (at least 5 lines)
Computers and Technology
2 answers:
shutvik [7]2 years ago
7 0

Answer:

Check the explanation

Explanation:

Code:

****************************************

import java.util.Random;

public class Matrices {

static int staticMatrix1[][] = new int [100][100];

static int staticMatrix2[][] = new int [100][100];

static int staticMatrix3[][] = new int [100][100];

public void localMatrices() {

int localMatrix1[][] = new int [100][100];

int localMatrix2[][] = new int [100][100];

int localMatrix3[][] = new int [100][100];

Random r = new Random();

for(int i =0;i<100;i++) {

for(int j =0;j<100;j++) {

localMatrix1[i][j] = r.nextInt(100);

localMatrix2[i][j] = r.nextInt(100);

}

}

long localStart = System.nanoTime();

multiplyLocal(localMatrix1, localMatrix2);

long localEnd = System.nanoTime();

System.out.println("Time taken for local multiplication: "+ (localEnd-localStart)/ 1000000);

}

public void multiplyLocal(int first[][],int second[][]) {

int[][] multiply = new int [100][100];

for (int c = 0; c < 100; c++)

{

for (int d = 0; d < 100; d++)

{  

int sum = 0;

for (int k = 0; k < 100; k++)

{

sum = sum + first[c][k]*second[k][d];

}

 

multiply[c][d] = sum;

sum = 0;

}

}

}

public static void multiplyStatic(int first[][],int second[][]) {

int[][] multiply = new int [100][100];

for (int c = 0; c < 100; c++)

{

for (int d = 0; d < 100; d++)

{  

int sum = 0;

for (int k = 0; k < 100; k++)

{

sum = sum + first[c][k]*second[k][d];

}

 

multiply[c][d] = sum;

sum = 0;

}

}

}

public static void main(String args[]) {

Random r = new Random();

for(int i = 0;i<100;i++) {

for(int j = 0;j<100;j++) {

staticMatrix1[i][j] = r.nextInt(100);

staticMatrix2[i][j] = r.nextInt(100);

}

}

long staticStart = System.nanoTime();

multiplyStatic(staticMatrix1, staticMatrix2);

long staticEnd = System.nanoTime();

System.out.println("Time taken for static multiplication: "+ (staticEnd-staticStart)/ 1000000);

Matrices matrices = new Matrices();

matrices.localMatrices();

}

}

***************************************

Outputs:

Time taken for static multiplication: 6

Time taken for local multiplication: 12

******************************************

Sveta_85 [38]2 years ago
4 0

Answer:

See explaination

Explanation:

Code below:

import java.util.Random;

public class Matrices {

static int staticMatrix1[][] = new int [100][100];

static int staticMatrix2[][] = new int [100][100];

static int staticMatrix3[][] = new int [100][100];

public void localMatrices() {

int localMatrix1[][] = new int [100][100];

int localMatrix2[][] = new int [100][100];

int localMatrix3[][] = new int [100][100];

Random r = new Random();

for(int i =0;i<100;i++) {

for(int j =0;j<100;j++) {

localMatrix1[i][j] = r.nextInt(100);

localMatrix2[i][j] = r.nextInt(100);

}

}

long localStart = System.nanoTime();

multiplyLocal(localMatrix1, localMatrix2);

long localEnd = System.nanoTime();

System.out.println("Time taken for local multiplication: "+ (localEnd-localStart)/ 1000000);

}

public void multiplyLocal(int first[][],int second[][]) {

int[][] multiply = new int [100][100];

for (int c = 0; c < 100; c++)

{

for (int d = 0; d < 100; d++)

{

int sum = 0;

for (int k = 0; k < 100; k++)

{

sum = sum + first[c][k]*second[k][d];

}

multiply[c][d] = sum;

sum = 0;

}

}

}

public static void multiplyStatic(int first[][],int second[][]) {

int[][] multiply = new int [100][100];

for (int c = 0; c < 100; c++)

{

for (int d = 0; d < 100; d++)

{

int sum = 0;

for (int k = 0; k < 100; k++)

{

sum = sum + first[c][k]*second[k][d];

}

multiply[c][d] = sum;

sum = 0;

}

}

}

public static void main(String args[]) {

Random r = new Random();

for(int i = 0;i<100;i++) {

for(int j = 0;j<100;j++) {

staticMatrix1[i][j] = r.nextInt(100);

staticMatrix2[i][j] = r.nextInt(100);

}

}

long staticStart = System.nanoTime();

multiplyStatic(staticMatrix1, staticMatrix2);

long staticEnd = System.nanoTime();

System.out.println("Time taken for static multiplication: "+ (staticEnd-staticStart)/ 1000000);

Matrices matrices = new Matrices();

matrices.localMatrices();

}

}

You might be interested in
Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards
konstantin123 [22]

Answer:

for(i = 0 ; i < NUM_VALS; ++i)

{

   cout << courseGrades[i] << " ";

}

cout << endl;

for(i = NUM_VALS-1 ; i >=0 ; --i)

{

   cout << courseGrades[i] << " ";

}

cout << endl;

Explanation:

The first loop initializes i with 0, because we have to print the elements in order in which the appear in the array. We print each element, adding a space (" ") character at its end. After the loop ends, we add a new line using endl.

The second loop will print the values in a reverse order, so we initialize it from NUM_VALS-1, (since NUM_VALS = 4, and array indices are 0,1,2,3). We execute the loop till i >= 0, and we print the space character and new line in a similar way we executed in loop1.

4 0
2 years ago
What type of firestopping technology expands as much as 25 times in volume?
love history [14]
The answer is Intumescent. I am pretty sure this is right.
7 0
3 years ago
Describe Relational Query Languages and Operations.
Lelechka [254]

Answer:

Relational query language is the language that is used in the queries of the relational databases that has rows and columns in table. The user or client presents a request for gaining the information from the database. The relationships in the database are defined in numerous ways which creates the query.

This language can be procedural form or non-procedural form.The operations performed by this language are communication with the relational database, analyzing the relationships between the entities of database,splitting the request from client and then execution of that request is done by database management system(DBMS), etc.

7 0
2 years ago
A storyboard is an example of an implementation tool.
alexdok [17]

Answer:

That's not true. A storyboard is an organizer to plan out certain things and to know how something should look before doing the finished product.

Explanation:

7 0
3 years ago
Jason wants to set up his Wi-Fi’s security. He cannot install a central server for authentication. However, he wants to use a pr
jolli1 [7]

Answer:

Answer = a ig

wpa. ig ig ig ig

4 0
2 years ago
Other questions:
  • Modern database tools support ________________, which entails separating data from the programs that manipulate data.
    14·1 answer
  • In Excel, what happens to the cell contents when you click and drag a cell into multiple cells?
    14·1 answer
  • Can Any body Define what is search engine in a simple language quick please​
    14·1 answer
  • Two different ways to bring up My Computer folder
    11·1 answer
  • function calculate () { var s = 2; var x = 2; var y = 3; if (x &gt; 4) { s=s+ 2; } else if ( y &gt; 4) { s=s+ 4; } else { s+=3;}
    11·1 answer
  • Which method will return the first element in an ArrayList employees?
    5·1 answer
  • The method needed to arrange for an object to be notified when a window's close-window button has been clicked is
    6·1 answer
  • I need help thanks please!
    8·2 answers
  • Identify similarities and differences of hibiscus leaves <br>​
    14·1 answer
  • Describe psychographic differences among the past five generations of Americans that you learned about in this course. What type
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!