-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
98 lines (79 loc) · 1.57 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<iostream>
#include<cmath>
#include<fstream>
#include<string>
#include "Matrix.hpp"
using namespace std;
int main()
{
// Create Matrix A
Matrix A(3,3);
int k = 0;
for (int i = 0; i<3; i++)
{
for(int j = 0; j<3; j++)
{
k++;
A(i,j) = k;
}
}
cout << "Matrix A " << endl << A << endl;
//Create Matrix B
Matrix B(3,3);
k=0;
for (int i = 0; i<3; i++)
{
for(int j = 0; j<3; j++)
{
k++;
B(i,j) = k;
}
}
cout << "Matrix B " << endl << B << endl;
// Matrx Matrix operations
//Addition
cout << "A + B" << endl<< A+B << endl;
//Subtraction
cout <<"A-B" << endl << A-B << endl;
// Multiplication
cout <<"A*B"<<endl<< A*B << endl;
// Matrix/Scalar
// Addition
cout << "A+2" << endl <<A+2. << endl;
// Subtraction
cout << "A-2" << endl << A-2. << endl;
// multiplication
cout << "A*2" << endl<< A*2. << endl;
// division
cout << "A/2" << endl << A/2.0 << endl;
// Vector definiton
Vector b(3);
b[0] = 1.;
b[1] = 2.;
b[2] = 3.;
cout << "Vector b " << endl << b << endl;
//Matrix/vector multiplication
cout << "A*b" << endl << A*b << endl;
///
// Solve
//Define Augmented Matrix
Matrix U(3,4);
k=0;
for(int i =0;i<3;i++)
{
for(int j=0;j<4;j++)
{
k++;
U(i,j) = k;
}
}
// define solution vector
Vector Sol(3);
Sol = U.Solve();
cout << "solution to matrix U " << endl << U << endl;
cout <<"is"<< endl<<Sol <<endl;
// Define Identity Matrix
Matrix Identity(3,3);
Identity=I(3,3);
cout <<"3x3 identity matrix"<<endl<< Identity << endl;
}