answer.
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
PtichkaEL [24]
2 years ago
14

Write a JavaScript to multiple 2 square matrices (3,3). You can use any numbers as elements of the matrix.

Computers and Technology
1 answer:
emmasim [6.3K]2 years ago
5 0

Answer:

Here is the JavaScript program:

function MatricesMul(matrix1, matrix2) {

   var product = [];

   for (var i = 0; i < matrix1.length; i++) {

       product[i] = [];

       for (var j = 0; j < matrix2[0].length; j++) {

           var total = 0;

           for (var k = 0; k < matrix1[0].length; k++) {

               total += matrix1[i][k] * matrix2[k][j];  }

           product[i][j] = total;        }    }

   return product;}

var matrix1 = [[1,2,3],[4,5,6],[7,8,9]]

var matrix2 = [[3,2,1],[6,5,4],[1,2,3]]

var output = MatricesMul(matrix1, matrix2)

document.write(output);

Explanation:

The function MatricesMul(matrix1, matrix2) takes two matrices (matrix1 and matrix2) as parameters.

var product = [];  product works as an array to contain the result of the multiplication of the two matrices matrix1 and matrix2.

for (var i = 0; i < matrix1.length; i++) this is a loop which iterates through the matrix1 and it continues to execute until the loop variable i exceeds the length of the matrix1. This is basically the loop which iterates through the rows of matrix1.

for (var j = 0; j < matrix2[0].length; j++) this is a loop which iterates through matrix2 and it continues to execute untill the loop variable j exceeds the length of the element of matrix2 at 0-th index (first element). This is basically the loop which iterates through the colulmns of matrix2.

var total = 0;  variable total is initialized to 0 and this variable is used to compute the sum.

for (var k = 0; k < matrix1[0].length; k++) this loop is used for the multiplication of the two matrices matrix1 and matrix2.

total += matrix1[i][k] * matrix2[k][j];  this statement first multiplies each element of matrix1 row to each element of the matrix2 column, takes the sum of pairwise products.

return product; returns the result of the multiplication of matrix1 and matrix2.

For example let matrix1 = [[1,2,3],[4,5,6],[7,8,9]]  and matrix2 = [[3,2,1],[6,5,4],[1,2,3]] .

The first for loop moves through each row of matrix1. The first element of first row of matrix1 is 1, the second element is 2 and third is 3. The second loop iterates through each column of matrix2. Lets take the first column matrix2. The first element of first column of matrix2 i.e. 3, the second element is 6 and the third is 1. Third loop performs the pairwise multiplication of row of matrix1 to column of matrix2 and takes the sum of pairwise product. This means 1 is multiplied to 3, 2 is multiplied with 6 and 3 is multiplied to 1. This will take the form: 1*3 + 2*6 + 3*1 = 3 + 12 + 3 Now their sum is taken and the result is stored in total variable. So the sum of 3 + 12 + 3 is 18. This process will continue until all the rows elements of matrix1 and elements in all columns of matrix2 are multiplied and the sum of each pairwise product is taken.

var matrix1 = [[1,2,3],[4,5,6],[7,8,9]]

var matrix2 = [[3,2,1],[6,5,4],[1,2,3]]

The above two statements two (3,3) square matrices are given values.

var output = MatricesMul() this calls the MatricesMul method and passes the two matrices (matrix1, matrix2) to the function and stores the result of this multiplication to output variable.

document.write(output); displays the result of the multiplication of two square matrices .

You might be interested in
Leena needs to manually update the TOC and would prefer not to change the styles in the document.
Lady_Fox [76]

<u>Answer:</u>

<em>Using References tab. Table of Contents group, Update Table </em>

<u>Explanation:</u>

Changes in the table of content is easy to do in word application. The changes might be only for a page number or heading or it might be anything. Based on the need, word allows you to do by using References tab.

<em>Step 1:</em><em> Goto References tab Contents group Update table </em>

<em>Step 2:</em><em> Choose Update Page number only to update only the page numbers in TOC. This would ignore the changes in headings. </em>

<em>Step 3:</em><em> Update Entire table would update the whole table. </em>

8 0
2 years ago
Read 2 more answers
What types of messages flow across an SDN controller’s northbound and southbound APIs? Who is the recipient of these messages se
Marta_Voda [28]

Answer and Explanation:

Messages flow across an SDN controller's:  

Northbound APIs:  

• Messages which help in read/write state of the network and developing flow tables within the  

state management layer.  

• Notifications for the state-change events.  

• The interaction between the controller and network control applications is done through the  

northbound interface.  

• Network control applications send messages to the controller.  

Southbound APIs:  

• Messages which help for the up-to-date view of the network's state like message for the  

attached link has gone up or down, new devices are joined the network, or indications of the  

device is up or down.  

• Controller's southbound interface is the communication among the controller and the controlled  

devices. Controlled devices are the recipients of the messages sent form the controller.  

3 0
2 years ago
A colleague sent you an awesome article about using proper ergonomics while sitting at the computer. You don't have time to read
lys-0071 [83]

Answer: Select the article attachment and save it to your computer.

Explanation:

5 0
2 years ago
Zander is beginning to take college courses to prepare for a career in computer science, which is the study of using logic to cr
scoundrel [369]

The answer is (A. career definition and career requirements  )


7 0
2 years ago
For a custom App uploaded to Microsoft Teams, if an organization wants to disallow users from updating the settings of the custo
GrogVix [38]

Answer:

canUpdateConfiguration

Explanation:

The user experience con be refined by enabling users to rename, modify, reconfigure, a channel or group tab by setting as true the property of the canUpdateConfiguration manifest file attribute

In the app, what takes place with regards to the content following the event of a tab removal can be specified by the inclusion of a removal options page and have a value set for the setSettings() configuration removeUrl property.  

3 0
2 years ago
Other questions:
  • Mary is writing an article about the animal kingdom. She wants to place image below the text. Which menu should Mary choose for
    15·2 answers
  • Which technology had the same effect in the 1920s as the internet did in the 2000s? the widespread effect of technology 1920s 20
    8·1 answer
  • Initialize the list short_names with strings 'Gus', 'Bob', and 'Zoe'. Sample output for the givenprogram:Gus Bob Zoeshort_names
    13·1 answer
  • What technology gets its name from the notion that it ignores the traditional A, B, and C class designations for IP addresses?
    14·1 answer
  • Assume the availability of a function is_prime. Assume a variable n has been associated with positive integer. Write the stateme
    15·1 answer
  • Nathan would like to save his PowerPoint presentation as a video that can be replayed easily on any device at full quality. Whic
    14·1 answer
  • #Write a function called fancy_find. fancy_find should have #two parameters: search_within and search_for. # #fancy_find should
    9·1 answer
  • Why is it important for element IDs to have meaningful names?
    11·1 answer
  • What is the function of napier's bones<br>​
    8·1 answer
  • To create a public key signature, you would use the ______ key.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!