Change matrix examples

main
Micke Nordin 2 years ago
parent e662c7bebd
commit 115cc01f79
Signed by: micke
GPG Key ID: 014B273D614BE877

@ -111,34 +111,36 @@ g++ -o matrix matrix.cpp
``` ```
*output* *output*
``` ```
The matrix m: The matrix m
| 7 | 6+i | | 1 | 1 |
| 5 | 3 | | 1 | 1 |
The matrix m roted by one pi radian:
| 6+i | 3 |
| 7 | 5 |
The determinant of matrix m: The determinant of matrix m:
-9-5i 0
The matrix m's transpose: The matrix n:
| 7 | 5 |
| 6+i | 3 |
The matrix m's diagonal:
| 7 |
| 3 |
The matrix m's off diagonal:
| 6+i |
| 5 |
The matrix n
| 2 | 1+i | | 2 | 1+i |
| 1-i | 5 | | 1-i | 5 |
The matrix n roted by one pi radian:
| 1+i | 5 |
| 2 | 1-i |
The determinant of matrix n: The determinant of matrix n:
8 8
The matrix n's transpose:
| 2 | 1-i |
| 1+i | 5 |
The matrix n's diagonal:
| 2 |
| 5 |
The matrix n's off diagonal:
| 1+i |
| 1-i |
The matrix m * n The matrix m * n
| 21-5i | 37+12i | | 3-i | 6+i |
| 13-3i | 20+5i | | 3-i | 6+i |
The matrix m is not hermitian, here is the hermitian conjugate: The matrix m + n
| 7 | 5 | | 3 | 2+i |
| 6-i | 3 | | 2-i | 6 |
Is 2 an eigenvalue of m?
Yes!
The matrix n is hermitian, here is the hermitian conjugate: The matrix n is hermitian, here is the hermitian conjugate:
| 2 | 1+i | | 2 | 1+i |
| 1-i | 5 | | 1-i | 5 |

@ -2,21 +2,20 @@
int main() { int main() {
vector a = vector(2); vector a = vector(2);
a[0] = cnumber(7, 0); a[0] = 1;
a[1] = cnumber(6, 1); a[1] = 1;
vector b = vector(2); vector b = vector(2);
b[0] = cnumber(5, 0); b[0] = 1;
b[1] = cnumber(3, 0); b[1] = cnumber(1, 0);
vector c = vector(2); vector c = vector(2);
c[0] = cnumber(2, 0); c[0] = 2;
c[1] = cnumber(1, 1); c[1] = cnumber(1, 1);
vector d = vector(2); vector d = vector(2);
d[0] = cnumber(1, -1); d[0] = cnumber(1, -1);
d[1] = cnumber(5, 0); d[1] = 5;
matrix m = matrix(2, 2); matrix m = matrix(2, 2);
m[0] = a; m[0] = a;
@ -26,28 +25,31 @@ int main() {
n[0] = c; n[0] = c;
n[1] = d; n[1] = d;
cout << "The matrix m:" << endl; cout << "The matrix m" << endl;
cout << m << endl; cout << m << endl;
cout << "The matrix m roted by one pi radian:" << endl;
cout << m.rotate_by_one_pi() << endl;
cout << "The determinant of matrix m:" << endl; cout << "The determinant of matrix m:" << endl;
cout << m.determinant() << endl; cout << m.determinant() << endl;
cout << "The matrix m's transpose:" << endl; cout << "The matrix n:" << endl;
cout << m.transpose() << endl;
cout << "The matrix m's diagonal:" << endl;
cout << m.get_diagonal() << endl;
cout << "The matrix m's off diagonal:" << endl;
cout << m.get_off_diagonal() << endl;
cout << "The matrix n" << endl;
cout << n << endl; cout << n << endl;
cout << "The matrix n roted by one pi radian:" << endl;
cout << n.rotate_by_one_pi() << endl;
cout << "The determinant of matrix n:" << endl; cout << "The determinant of matrix n:" << endl;
cout << n.determinant() << endl; cout << n.determinant() << endl;
cout << "The matrix n's transpose:" << endl;
cout << n.transpose() << endl;
cout << "The matrix n's diagonal:" << endl;
cout << n.get_diagonal() << endl;
cout << "The matrix n's off diagonal:" << endl;
cout << n.get_off_diagonal() << endl;
cout << "The matrix m * n" << endl; cout << "The matrix m * n" << endl;
cout << m * n << endl; cout << m * n << endl;
if (!m.is_hermitian()) { cout << "The matrix m + n" << endl;
cout << "The matrix m is not hermitian, here is the hermitian conjugate:" cout << m + n << endl;
<< endl; cout << "Is 2 an eigenvalue of m?" << endl;
cout << m.hermitian_conjugate() << endl; if (m.is_eigenvalue(2)) {
cout << "Yes!" << endl;
} else {
cout << "No!" << endl;
} }
if (n.is_hermitian()) { if (n.is_hermitian()) {
cout << "The matrix n is hermitian, here is the hermitian conjugate:" cout << "The matrix n is hermitian, here is the hermitian conjugate:"

Loading…
Cancel
Save