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