Please enter valid numbers for all matrix elements.
';
return;
}
var html = ";
html += 'Result of ' + operation + ':';
html += '
';
html += '
' + matrix[0][0] + '
';
html += '
' + matrix[0][1] + '
';
html += '
' + matrix[1][0] + '
';
html += '
' + matrix[1][1] + '
';
html += '
';
resultDiv.innerHTML = html;
}
function calculateMatrixAddition() {
var matrixA = getMatrixA();
var matrixB = getMatrixB();
if (!matrixA || !matrixB) {
displayMatrixResult(null, 'Addition');
return;
}
var resultMatrix = [
[matrixA[0][0] + matrixB[0][0], matrixA[0][1] + matrixB[0][1]],
[matrixA[1][0] + matrixB[1][0], matrixA[1][1] + matrixB[1][1]]
];
displayMatrixResult(resultMatrix, 'Matrix A + Matrix B');
}
function calculateMatrixSubtraction() {
var matrixA = getMatrixA();
var matrixB = getMatrixB();
if (!matrixA || !matrixB) {
displayMatrixResult(null, 'Subtraction');
return;
}
var resultMatrix = [
[matrixA[0][0] – matrixB[0][0], matrixA[0][1] – matrixB[0][1]],
[matrixA[1][0] – matrixB[1][0], matrixA[1][1] – matrixB[1][1]]
];
displayMatrixResult(resultMatrix, 'Matrix A – Matrix B');
}
function calculateScalarMultiplication() {
var matrixA = getMatrixA();
var scalar = getScalar();
if (!matrixA || scalar === null) {
displayMatrixResult(null, 'Scalar Multiplication');
return;
}
var resultMatrix = [
[matrixA[0][0] * scalar, matrixA[0][1] * scalar],
[matrixA[1][0] * scalar, matrixA[1][1] * scalar]
];
displayMatrixResult(resultMatrix, 'Scalar * Matrix A');
}
Understanding Matrix Operations
Matrices are fundamental mathematical objects used extensively in various fields like physics, engineering, computer graphics, economics, and statistics. A matrix is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. Each item in a matrix is called an element or entry.
What is a Matrix?
A matrix is typically denoted by a capital letter, for example, A or B. The size or dimension of a matrix is given by the number of rows and columns it has. A matrix with 'm' rows and 'n' columns is called an m x n matrix. For instance, a 2×2 matrix has two rows and two columns, like the ones used in our calculator:
A = [a11a21a12a22]
Where aij refers to the element in the i-th row and j-th column.
Matrix Addition
To add two matrices, they must have the same dimensions (same number of rows and columns). The addition is performed by adding the corresponding elements. If A and B are two m x n matrices, their sum C = A + B is also an m x n matrix where each element cij = aij + bij.
Example of Matrix Addition:
Let's use the default values in the calculator:
A = [1324]
B = [5768]
A + B = [1+53+72+64+8]
=
[610812]
Matrix Subtraction
Similar to addition, matrix subtraction also requires matrices of the same dimensions. You subtract the corresponding elements. If C = A – B, then cij = aij – bij.
Example of Matrix Subtraction:
Using the same matrices A and B:
A – B = [1-53-72-64-8]
=
[-4-4-4-4]
Scalar Multiplication
Scalar multiplication involves multiplying a matrix by a single number (a scalar). Each element of the matrix is multiplied by that scalar. If C = kA, where k is a scalar, then cij = k * aij.
Example of Scalar Multiplication:
Let's use Matrix A and the default scalar value of 2:
2 * A = 2 * [1324]
=
[2*12*32*22*4]
=
[2648]
This calculator provides a simple way to perform these basic 2×2 matrix operations, which are foundational for more complex linear algebra concepts.