Download MPCMath User Manual - 2
Transcript
1.2. MATRICES
9
// Matrix definition
Matrix A = new Matrix(MatrixForm.General, 3, 5);
Matrix B = Matrix.Random(3, 5, -100.0, 100.0);
Matrix C;
A[2,3] = 25.0;
C = A + B;
Matrix.Show("A", A);
Matrix.Show("B", B);
Matrix.Show("C", C);
These statements defines matrix A with 3 rows and 5 columns. Matrix B is
defined as a 3 rows 5 columns matrix with random elements in the range -100.0
to 100.0. Element [2,3] of A is set to 25.0, and matrix C is the sum of matrix A
and B. The Matrix.Show calls displays the matrices:
A Matrix.Form General[3,5]
0
0
0
0
0
0
0
0
0
0
0
25,0000
0
0
0
B Matrix.Form General[3,5]
-87,4640 -74,9052
50,3092
-82,9797
27,8304
5,4292
7,0211
19,3501
98,1663
-14,7262
-4,7578
27,1058
-73,6282
61,5226
58,8416
C Matrix.Form General[3,5]
-87,4640 -74,9052
50,3092
-82,9797
27,8304
5,4292
7,0211
19,3501
98,1663
-14,7262
-4,7578
52,1058
-73,6282
61,5226
58,8416
The matrix standard functionality includes Add, Sub, Mul, Transpose, MulTransposed, Clone, Negate, Invert, Eigenvalues, SVD decompositions. As for
Vectors the Matrix objects support +, -, * operators
int
x =
A =
B =
dim = 5;
Vector.Random(dim, -50.0, 50.0);
Matrix.Random(dim, dim, -50.0, 50.0);
Matrix.Random(dim, dim, -50.0, 50.0);
y = (A + B) * x;
Vector.Show("x",
Matrix.Show("A",
Matrix.Show("B",
Vector.Show("y",
x);
A);
B);
y);