|
|
|
@ -8,20 +8,20 @@ void cnumber_main() {
|
|
|
|
|
cnumber a(3, 2);
|
|
|
|
|
cnumber b(4, -3);
|
|
|
|
|
|
|
|
|
|
cout << "a = " << a << endl;
|
|
|
|
|
cout << "a* = " << a.conjugate() << endl;
|
|
|
|
|
cout << "a*a* = " << a * a.conjugate() << endl;
|
|
|
|
|
cout << "b = " << b << endl;
|
|
|
|
|
cout << "b* = " << b.conjugate() << endl;
|
|
|
|
|
cout << "b*b* = " << b * b.conjugate() << endl;
|
|
|
|
|
cout << "a + b = " << a + b << endl;
|
|
|
|
|
cout << "(a + b)* = " << (a + b).conjugate() << endl;
|
|
|
|
|
cout << "a - b = " << a - b << endl;
|
|
|
|
|
cout << "(a - b)* = " << (a - b).conjugate() << endl;
|
|
|
|
|
cout << "a * b = " << a * b << endl;
|
|
|
|
|
cout << "(a * b)* = " << (a * b).conjugate() << endl;
|
|
|
|
|
cout << "a / b = " << a / b << endl;
|
|
|
|
|
cout << "(a / b)* = " << (a / b).conjugate() << endl;
|
|
|
|
|
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() {
|
|
|
|
@ -33,20 +33,20 @@ void fraction_main() {
|
|
|
|
|
fraction q(a, b);
|
|
|
|
|
fraction q2(c, d);
|
|
|
|
|
fraction q3(e);
|
|
|
|
|
cout.precision(10);
|
|
|
|
|
cout << a << "/" << b << '=' << q << endl;
|
|
|
|
|
cout << a << "/" << b << '=' << q.to_double() << endl;
|
|
|
|
|
cout << c << "/" << d << '=' << q2 << endl;
|
|
|
|
|
cout << c << "/" << d << '=' << q2.to_double() << endl;
|
|
|
|
|
cout << q << "+" << q2 << '=' << q + q2 << endl;
|
|
|
|
|
cout << q << "+" << q2 << '=' << (q + q2).to_double() << endl;
|
|
|
|
|
cout << q << "-" << q2 << '=' << q - q2 << endl;
|
|
|
|
|
cout << q << "-" << q2 << '=' << (q - q2).to_double() << endl;
|
|
|
|
|
cout << q << "*" << q2 << '=' << q * q2 << endl;
|
|
|
|
|
cout << q << "*" << q2 << '=' << (q * q2).to_double() << endl;
|
|
|
|
|
cout << q << "/" << q2 << '=' << q / q2 << endl;
|
|
|
|
|
cout << q << "/" << q2 << '=' << (q / q2).to_double() << endl;
|
|
|
|
|
cout << e << '=' << q3 << endl;
|
|
|
|
|
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() {
|
|
|
|
@ -74,42 +74,42 @@ void matrix_main() {
|
|
|
|
|
n[0] = c;
|
|
|
|
|
n[1] = d;
|
|
|
|
|
|
|
|
|
|
cout << "The matrix m" << endl;
|
|
|
|
|
cout << m << endl;
|
|
|
|
|
cout << "The determinant of matrix m:" << endl;
|
|
|
|
|
cout << m.determinant() << endl;
|
|
|
|
|
cout << "The matrix 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 << 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 vector d:" << endl;
|
|
|
|
|
cout << d << endl;
|
|
|
|
|
cout << "The matrix n * the vector d" << endl;
|
|
|
|
|
cout << n * d << endl;
|
|
|
|
|
cout << "The vector d * the matrix n" << endl;
|
|
|
|
|
cout << d * n << endl;
|
|
|
|
|
cout << "The matrix m * n" << endl;
|
|
|
|
|
cout << m * n << endl;
|
|
|
|
|
cout << "The matrix m + n" << endl;
|
|
|
|
|
cout << m + n << endl;
|
|
|
|
|
cout << "Is 2 an eigenvalue of m?" << endl;
|
|
|
|
|
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 by one pi radian:" << std::endl;
|
|
|
|
|
std::cout << n.rotate_by_one_pi() << 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)) {
|
|
|
|
|
cout << "Yes!" << endl;
|
|
|
|
|
std::cout << "Yes!" << std::endl;
|
|
|
|
|
} else {
|
|
|
|
|
cout << "No!" << endl;
|
|
|
|
|
std::cout << "No!" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
if (n.is_hermitian()) {
|
|
|
|
|
cout << "The matrix n is hermitian, here is the hermitian conjugate:"
|
|
|
|
|
<< endl;
|
|
|
|
|
cout << n.hermitian_conjugate() << endl;
|
|
|
|
|
std::cout << "The matrix n is hermitian, here is the hermitian conjugate:"
|
|
|
|
|
<< std::endl;
|
|
|
|
|
std::cout << n.hermitian_conjugate() << std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void vector_main() {
|
|
|
|
@ -128,30 +128,30 @@ void vector_main() {
|
|
|
|
|
w[0] = three;
|
|
|
|
|
w[1] = four;
|
|
|
|
|
w[2] = five;
|
|
|
|
|
cout << "v:" << endl;
|
|
|
|
|
cout << v << endl;
|
|
|
|
|
cout << "w:" << endl;
|
|
|
|
|
cout << w << endl;
|
|
|
|
|
cout << "v + w:" << endl;
|
|
|
|
|
cout << v + w << endl;
|
|
|
|
|
cout << "v - w:" << endl;
|
|
|
|
|
cout << v - w << endl;
|
|
|
|
|
cout << "v * w:" << endl;
|
|
|
|
|
cout << v * w << endl;
|
|
|
|
|
cout << "w * i:" << endl;
|
|
|
|
|
cout << w * i << endl;
|
|
|
|
|
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 (long long j = 0; j < v.get_dimention(); j++) {
|
|
|
|
|
cout << "Element " << j << " of v:" << endl;
|
|
|
|
|
cout << v[j] << endl;
|
|
|
|
|
std::cout << "Element " << j << " of v:" << std::endl;
|
|
|
|
|
std::cout << v[j] << std::endl;
|
|
|
|
|
}
|
|
|
|
|
cout << "A temp vector of dimension 3" << endl << vector(3) << endl;
|
|
|
|
|
std::cout << "A temp vector of dimension 3" << std::endl << vector(3) << std::endl;
|
|
|
|
|
vector k = vector(3);
|
|
|
|
|
k = w;
|
|
|
|
|
cout << "Assignment of w to k" << endl << k << endl;
|
|
|
|
|
cout << "Manually set elements of k to elements of v" << endl;
|
|
|
|
|
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 (long long j = 0; j < v.get_dimention(); j++)
|
|
|
|
|
k[j] = v[j];
|
|
|
|
|
cout << k << endl;
|
|
|
|
|
std::cout << k << std::endl;
|
|
|
|
|
}
|
|
|
|
|
int main() {
|
|
|
|
|
fraction_main();
|
|
|
|
|