mmathlib/matrix.cpp

61 lines
1.4 KiB
C++
Raw Normal View History

2022-07-16 12:53:07 +02:00
#include "matrix.hpp"
int main() {
2022-07-16 17:30:59 +02:00
vector a = vector(2);
2022-07-18 15:41:22 +02:00
a[0] = 1;
a[1] = 1;
2022-07-16 12:53:07 +02:00
2022-07-16 17:30:59 +02:00
vector b = vector(2);
2022-07-18 15:41:22 +02:00
b[0] = 1;
b[1] = cnumber(1, 0);
2022-07-16 12:53:07 +02:00
2022-07-16 17:30:59 +02:00
vector c = vector(2);
2022-07-18 15:41:22 +02:00
c[0] = 2;
c[1] = cnumber(1, 1);
2022-07-16 12:58:25 +02:00
2022-07-16 17:30:59 +02:00
vector d = vector(2);
d[0] = cnumber(1, -1);
2022-07-18 15:41:22 +02:00
d[1] = 5;
2022-07-16 17:30:59 +02:00
matrix m = matrix(2, 2);
2022-07-16 12:58:25 +02:00
m[0] = a;
m[1] = b;
2022-07-16 17:30:59 +02:00
matrix n = matrix(2, 2);
n[0] = c;
n[1] = d;
2022-07-16 12:53:07 +02:00
2022-07-18 15:41:22 +02:00
cout << "The matrix m" << endl;
2022-07-16 12:53:07 +02:00
cout << m << endl;
2022-07-17 13:19:02 +02:00
cout << "The determinant of matrix m:" << endl;
cout << m.determinant() << endl;
2022-07-18 15:41:22 +02:00
cout << "The matrix n:" << endl;
2022-07-16 17:30:59 +02:00
cout << n << endl;
2022-07-18 15:41:22 +02:00
cout << "The matrix n roted by one pi radian:" << endl;
cout << n.rotate_by_one_pi() << endl;
2022-07-17 13:19:02 +02:00
cout << "The determinant of matrix n:" << endl;
cout << n.determinant() << endl;
2022-07-18 15:41:22 +02:00
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;
2022-07-16 17:30:59 +02:00
cout << "The matrix m * n" << endl;
cout << m * n << endl;
2022-07-18 15:41:22 +02:00
cout << "The matrix m + n" << endl;
cout << m + n << endl;
cout << "Is 2 an eigenvalue of m?" << endl;
if (m.is_eigenvalue(2)) {
cout << "Yes!" << endl;
} else {
cout << "No!" << endl;
2022-07-16 14:10:50 +02:00
}
2022-07-18 15:41:22 +02:00
if (n.is_hermitian()) {
cout << "The matrix n is hermitian, here is the hermitian conjugate:"
2022-07-16 17:30:59 +02:00
<< endl;
cout << n.hermitian_conjugate() << endl;
}
2022-07-16 12:53:07 +02:00
return 0;
}