You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
5.1 KiB
163 lines
5.1 KiB
#include "cnumber.hpp"
|
|
#include "fractions.hpp"
|
|
#include "matrix.hpp"
|
|
#include "vector.hpp"
|
|
#include <iostream>
|
|
|
|
void cnumber_main() {
|
|
cnumber a(3, 2);
|
|
cnumber b(4, -3);
|
|
|
|
std::cout << "a = " << a << std::endl;
|
|
std::cout << "a* = " << a.conjugate() << std::endl;
|
|
std::cout << "a*a* = " << a * a.conjugate() << std::endl;
|
|
std::cout << "b = " << b << std::endl;
|
|
std::cout << "b* = " << b.conjugate() << std::endl;
|
|
std::cout << "b*b* = " << b * b.conjugate() << std::endl;
|
|
std::cout << "a + b = " << a + b << std::endl;
|
|
std::cout << "(a + b)* = " << (a + b).conjugate() << std::endl;
|
|
std::cout << "a - b = " << a - b << std::endl;
|
|
std::cout << "(a - b)* = " << (a - b).conjugate() << std::endl;
|
|
std::cout << "a * b = " << a * b << std::endl;
|
|
std::cout << "(a * b)* = " << (a * b).conjugate() << std::endl;
|
|
std::cout << "a / b = " << a / b << std::endl;
|
|
std::cout << "(a / b)* = " << (a / b).conjugate() << std::endl;
|
|
}
|
|
|
|
void fraction_main() {
|
|
int a = 7;
|
|
int b = 3;
|
|
int c = 1;
|
|
int d = 11;
|
|
double e = 0.75;
|
|
fraction q(a, b);
|
|
fraction q2(c, d);
|
|
fraction q3(e);
|
|
std::cout.precision(10);
|
|
std::cout << a << "/" << b << '=' << q << std::endl;
|
|
std::cout << a << "/" << b << '=' << q.to_double() << std::endl;
|
|
std::cout << c << "/" << d << '=' << q2 << std::endl;
|
|
std::cout << c << "/" << d << '=' << q2.to_double() << std::endl;
|
|
std::cout << q << "+" << q2 << '=' << q + q2 << std::endl;
|
|
std::cout << q << "+" << q2 << '=' << (q + q2).to_double() << std::endl;
|
|
std::cout << q << "-" << q2 << '=' << q - q2 << std::endl;
|
|
std::cout << q << "-" << q2 << '=' << (q - q2).to_double() << std::endl;
|
|
std::cout << q << "*" << q2 << '=' << q * q2 << std::endl;
|
|
std::cout << q << "*" << q2 << '=' << (q * q2).to_double() << std::endl;
|
|
std::cout << q << "/" << q2 << '=' << q / q2 << std::endl;
|
|
std::cout << q << "/" << q2 << '=' << (q / q2).to_double() << std::endl;
|
|
std::cout << e << '=' << q3 << std::endl;
|
|
}
|
|
|
|
void matrix_main() {
|
|
vector a = vector(2);
|
|
a[0] = 1;
|
|
a[1] = 1;
|
|
|
|
vector b = vector(2);
|
|
b[0] = 1;
|
|
b[1] = cnumber(1, 0);
|
|
|
|
vector c = vector(2);
|
|
c[0] = 2;
|
|
c[1] = cnumber(1, 1);
|
|
|
|
vector d = vector(2);
|
|
d[0] = cnumber(1, -1);
|
|
d[1] = 5;
|
|
|
|
matrix m = matrix(2, 2);
|
|
m[0] = a;
|
|
m[1] = b;
|
|
|
|
matrix n = matrix(2, 2);
|
|
n[0] = c;
|
|
n[1] = d;
|
|
|
|
std::cout << "The matrix m" << std::endl;
|
|
std::cout << m << std::endl;
|
|
std::cout << "The determinant of matrix m:" << std::endl;
|
|
std::cout << m.determinant() << std::endl;
|
|
std::cout << "The matrix n:" << std::endl;
|
|
std::cout << n << std::endl;
|
|
std::cout << "The matrix n roted:" << std::endl;
|
|
std::cout << n.rotate() << std::endl;
|
|
std::cout << "The determinant of matrix n:" << std::endl;
|
|
std::cout << n.determinant() << std::endl;
|
|
std::cout << "The matrix n's transpose:" << std::endl;
|
|
std::cout << n.transpose() << std::endl;
|
|
std::cout << "The matrix n's diagonal:" << std::endl;
|
|
std::cout << n.get_diagonal() << std::endl;
|
|
std::cout << "The matrix n's off diagonal:" << std::endl;
|
|
std::cout << n.get_off_diagonal() << std::endl;
|
|
std::cout << "The vector d:" << std::endl;
|
|
std::cout << d << std::endl;
|
|
std::cout << "The matrix n * the vector d" << std::endl;
|
|
std::cout << n * d << std::endl;
|
|
std::cout << "The vector d * the matrix n" << std::endl;
|
|
std::cout << d * n << std::endl;
|
|
std::cout << "The matrix m * n" << std::endl;
|
|
std::cout << m * n << std::endl;
|
|
std::cout << "The matrix m + n" << std::endl;
|
|
std::cout << m + n << std::endl;
|
|
std::cout << "Is 2 an eigenvalue of m?" << std::endl;
|
|
if (m.is_eigenvalue(2)) {
|
|
std::cout << "Yes!" << std::endl;
|
|
} else {
|
|
std::cout << "No!" << std::endl;
|
|
}
|
|
if (n.is_hermitian()) {
|
|
std::cout << "The matrix n is hermitian, here is the hermitian conjugate:"
|
|
<< std::endl;
|
|
std::cout << n.hermitian_conjugate() << std::endl;
|
|
}
|
|
}
|
|
void vector_main() {
|
|
vector v = vector(3);
|
|
cnumber one(1, 0);
|
|
cnumber two(2, 0);
|
|
cnumber three(3, 0);
|
|
cnumber four(4, 0);
|
|
cnumber five(5, 0);
|
|
cnumber i(0, 1);
|
|
v[0] = one;
|
|
v[1] = two;
|
|
v[2] = i;
|
|
|
|
vector w = vector(3);
|
|
w[0] = three;
|
|
w[1] = four;
|
|
w[2] = five;
|
|
std::cout << "v:" << std::endl;
|
|
std::cout << v << std::endl;
|
|
std::cout << "w:" << std::endl;
|
|
std::cout << w << std::endl;
|
|
std::cout << "v + w:" << std::endl;
|
|
std::cout << v + w << std::endl;
|
|
std::cout << "v - w:" << std::endl;
|
|
std::cout << v - w << std::endl;
|
|
std::cout << "v * w:" << std::endl;
|
|
std::cout << v * w << std::endl;
|
|
std::cout << "w * i:" << std::endl;
|
|
std::cout << w * i << std::endl;
|
|
for (uint64_t j = 0; j < v.get_dimention(); j++) {
|
|
std::cout << "Element " << j << " of v:" << std::endl;
|
|
std::cout << v[j] << std::endl;
|
|
}
|
|
std::cout << "A temp vector of dimension 3" << std::endl << vector(3) << std::endl;
|
|
vector k = vector(3);
|
|
k = w;
|
|
std::cout << "Assignment of w to k" << std::endl << k << std::endl;
|
|
std::cout << "Manually set elements of k to elements of v" << std::endl;
|
|
for (uint64_t j = 0; j < v.get_dimention(); j++)
|
|
k[j] = v[j];
|
|
std::cout << k << std::endl;
|
|
}
|
|
int main() {
|
|
fraction_main();
|
|
cnumber_main();
|
|
vector_main();
|
|
matrix_main();
|
|
return 0;
|
|
}
|