-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
146 lines (131 loc) · 2.79 KB
/
main.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "Matrix.hpp"
#include "time.h"
int main()
{
/*HOMEWORK_1_
double a[84*84]={0};
double b[84];
for(int i=0; i<84; ++i)
{
switch(i)
{
case 0:
{
b[i] = 7;
a[0] = 6;
a[1] = 1;
break;
}
case 83:
{
b[i] = 14;
a[84*i+82] = 8;
a[84*i+83] = 6;
break;
}
default:
{
b[i] = 15;
int pos = 85*i;
a[pos-1] = 8;
a[pos] = 6;
a[pos+1] = 1;
break;
}
}
}
// double c[3] = {3,2,1};
Matrix A(84,84,a);
Matrix B(84,1,b);
// A.print();
cout << "Here are answers by selecting no pivot: " << endl;
Matrix X = A.sle(B, nonpivot);
X.print();
cout << "Here are answers by selecting column pivot: " << endl;
X = A.sle(B, colpivot);
X.print();
// A.gauss();
*/
/*example
double a[16] =
{
16, 4, 8, 4,
4,10, 8, 4,
8, 8,12,10,
4, 4,10,12
};
double b[4] =
{
32,
26,
38,
30
};
SymmetricalPositiveMatrix A(4,4,a);
Matrix B(4,1,b);
Matrix x = A.sle(B,2);
x.print();
*/
/*
double a[40*40] = {0};
for(int i=0; i<40; ++i)
{
switch(i)
{
case 0:
{
a[0] = 10;
a[1] = 1;
break;
}
case 39:
{
a[39*38] = 1;
a[39*40+39] = 10;
}
default:
{
a[i*40+i-1] = 1;
a[i*40+i] = 10;
a[i*40+i+1] = 1;
}
}
}
double b[40] = {0};
for(int i=0; i<40; ++i)
{
for(int j=1; j<=40; ++j)
{
b[i] = b[i] + (1.0/(i+j));
}
}
clock_t start,end;
cout << "solve linear equations by column pivot method:" << endl;
Matrix A(40,40,a);
Matrix B(40,1,b);
start = clock();
Matrix x = A.sle(B,1);
end = clock();
x.print();
double dur = end - start;
cout << "using time " << dur << endl << endl;
cout << "solve linear equations by " << endl;
SymmetricalPositiveMatrix SA(40,40,a);
start = clock();
Matrix Sx = SA.sle(B,2);
end = clock();
dur = end - start;
Sx.print();
cout << "using time " << dur << endl << endl;
Matrix diff = x - Sx;
cout << "First answer substracts the second answer: " << endl;
diff.print();
*/
double a[4] = {375,374,752,750};
double b[2] = {1,1};
Matrix A(2,2,a);
Matrix B(2,1,b);
Matrix x = A.sle(B);
x.print();
return 0;
}