Multiplication Matrix Calculator

Matrix Multiplication Calculator (3×3)

Matrix A

x

Matrix B

.calculator-container { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f9f9f9; padding: 25px; border-radius: 10px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); max-width: 800px; margin: 30px auto; border: 1px solid #ddd; } .calculator-container h2 { text-align: center; color: #333; margin-bottom: 25px; font-size: 1.8em; } .matrix-input-section { display: flex; justify-content: center; align-items: center; gap: 20px; margin-bottom: 25px; flex-wrap: wrap; } .matrix-box { background-color: #fff; border: 1px solid #e0e0e0; border-radius: 8px; padding: 15px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); text-align: center; } .matrix-box h3 { color: #555; margin-top: 0; margin-bottom: 15px; font-size: 1.2em; } .matrix-grid { display: grid; grid-template-columns: repeat(3, 60px); gap: 10px; justify-content: center; } .matrix-grid input[type="number"] { width: 55px; padding: 8px 5px; border: 1px solid #ccc; border-radius: 5px; font-size: 1em; text-align: center; -moz-appearance: textfield; /* Firefox */ } .matrix-grid input[type="number"]::-webkit-outer-spin-button, .matrix-grid input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; } .matrix-operator { font-size: 2.5em; font-weight: bold; color: #666; } .calculate-button { display: block; width: fit-content; margin: 20px auto 30px auto; padding: 12px 25px; background-color: #007bff; color: white; border: none; border-radius: 7px; font-size: 1.1em; cursor: pointer; transition: background-color 0.3s ease, transform 0.2s ease; } .calculate-button:hover { background-color: #0056b3; transform: translateY(-2px); } .calculate-button:active { transform: translateY(0); } .result-section { background-color: #eaf6ff; border: 1px solid #b3d9ff; border-radius: 8px; padding: 20px; margin-top: 25px; text-align: center; min-height: 100px; display: flex; flex-direction: column; justify-content: center; align-items: center; } .result-section h3 { color: #0056b3; margin-top: 0; margin-bottom: 15px; font-size: 1.3em; } .matrix-table { border-collapse: collapse; margin: 0 auto; background-color: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.05); border-radius: 8px; overflow: hidden; /* Ensures border-radius applies to table */ } .matrix-table td { border: 1px solid #cce0ff; padding: 12px 18px; text-align: center; font-size: 1.1em; color: #333; min-width: 70px; } .matrix-table tr:first-child td { border-top: none; } .matrix-table tr:last-child td { border-bottom: none; } .matrix-table td:first-child { border-left: none; } .matrix-table td:last-child { border-right: none; } .result-section p { color: #d9534f; font-weight: bold; } function calculateMatrixMultiplication() { var A = []; var B = []; var C = [[0,0,0],[0,0,0],[0,0,0]]; // Initialize result matrix for 3×3 // Populate Matrix A and B from input fields for (var i = 0; i < 3; i++) { A[i] = []; B[i] = []; for (var j = 0; j < 3; j++) { var aVal = parseFloat(document.getElementById('A' + (i+1) + (j+1)).value); var bVal = parseFloat(document.getElementById('B' + (i+1) + (j+1)).value); if (isNaN(aVal) || isNaN(bVal)) { document.getElementById('matrixResult').innerHTML = 'Please enter valid numbers for all matrix elements.'; return; } A[i][j] = aVal; B[i][j] = bVal; } } // Perform matrix multiplication (C = A * B) // C_ij = sum(A_ik * B_kj) for k from 0 to 2 for (var i = 0; i < 3; i++) { // rows of C (and A) for (var j = 0; j < 3; j++) { // columns of C (and B) C[i][j] = 0; // Initialize element C_ij for (var k = 0; k < 3; k++) { // inner dimension (columns of A, rows of B) C[i][j] += A[i][k] * B[k][j]; } } } // Display the result matrix var resultHTML = '

Resulting Matrix C (A x B):

'; resultHTML += ''; for (var i = 0; i < 3; i++) { resultHTML += ''; for (var j = 0; j < 3; j++) { resultHTML += ''; // Format to 4 decimal places } resultHTML += ''; } resultHTML += '
' + C[i][j].toFixed(4) + '
'; document.getElementById('matrixResult').innerHTML = resultHTML; }

Understanding Matrix Multiplication

Matrix multiplication is a fundamental operation in linear algebra with wide-ranging applications in mathematics, physics, engineering, computer graphics, and data science. Unlike scalar multiplication (where you multiply each element by a single number), matrix multiplication involves a more complex process that combines rows from the first matrix with columns from the second matrix.

What is a Matrix?

A matrix is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. The size or dimension of a matrix is defined by the number of its rows and columns (e.g., a 3×3 matrix has 3 rows and 3 columns).

Conditions for Matrix Multiplication

For two matrices, A and B, to be multiplied to form a product matrix C (i.e., C = A x B), a crucial condition must be met: the number of columns in the first matrix (A) must be equal to the number of rows in the second matrix (B).

  • If Matrix A has dimensions (m x n) and Matrix B has dimensions (n x p), then the resulting Matrix C will have dimensions (m x p).
  • The "inner" dimensions (n and n) must match. The "outer" dimensions (m and p) determine the size of the product matrix.

Our calculator focuses on 3×3 matrices, where A (3×3) multiplied by B (3×3) results in C (3×3).

How Matrix Multiplication Works (Element by Element)

Each element in the product matrix C, denoted as Cij, is calculated by taking the dot product of the i-th row of Matrix A and the j-th column of Matrix B. The formula for an element Cij is:

Cij = Σ (Aik * Bkj)

Where:

  • i represents the row index of matrix C (and A).
  • j represents the column index of matrix C (and B).
  • k is an index that runs from 1 to the number of columns in A (or rows in B).
  • Aik is the element in the i-th row and k-th column of Matrix A.
  • Bkj is the element in the k-th row and j-th column of Matrix B.

Example Calculation (for a single element)

Let's consider two 3×3 matrices, A and B, and calculate the element C11 (first row, first column of the product matrix C).

Given:

Matrix A =

A11A12A13
A21A22A23
A31A32A33

Matrix B =

B11B12B13
B21B22B23
B31B32B33

To find C11:

C11 = (A11 * B11) + (A12 * B21) + (A13 * B31)

Using the default values in the calculator (A11=1, A12=2, A13=3 and B11=9, B21=6, B31=3):

C11 = (1 * 9) + (2 * 6) + (3 * 3)

C11 = 9 + 12 + 9

C11 = 30

This process is repeated for every element in the resulting matrix C.

Applications of Matrix Multiplication

Matrix multiplication is not just a theoretical concept; it's a powerful tool used in many practical fields:

  • Computer Graphics: Used for transformations like rotation, scaling, and translation of 3D objects.
  • Physics and Engineering: Solving systems of linear equations, quantum mechanics, structural analysis.
  • Data Science and Machine Learning: Core operation in algorithms like neural networks, principal component analysis (PCA), and linear regression.
  • Economics: Modeling economic systems and input-output analysis.
  • Cryptography: Encoding and decoding messages.

This calculator provides a straightforward way to perform 3×3 matrix multiplication, helping you understand and verify these operations quickly.

Leave a Reply

Your email address will not be published. Required fields are marked *