-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
84 lines (71 loc) · 1.5 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
//Gil Parnon, MTH 399, General implementation of things like matrix times a vector in CSR
#include "csrMatrix.h"
#include <iostream>
using namespace std;
int main()
{
//Temp storage
int SIZE = 3;
float temp[SIZE];
float ** A = readIn(SIZE,9);
float ** L = new float*[SIZE];
float ** U = new float*[SIZE];
//Create a copy of the matrix
float ** A2 = new float*[SIZE];
//Initialization of the matrices
for(int i = 0; i < SIZE; ++i)
{
U[i] = new float[SIZE];
L[i] = new float[SIZE];
A2[i] = new float[SIZE];
for(int j = 0; j < SIZE; ++j)
{
A2[i][j] = A[i][j];
U[i][j] = 0;
L[i][j] = 0;
}
}
//This will do LU decomposition on A into an L and U.
LU_Factor(A2,SIZE,L,U);
matrix L_CSR(L,SIZE);
L_CSR.display();
matrix U_CSR(U,SIZE);
U_CSR.display();
cout << "What is x?" << '\n';
for(int i =0; i < SIZE; ++i)
{
cout << "x" << i << ": ";
cin >> temp[i];
cin.ignore(100,'\n');
cout << '\n';
}
vector x(temp,SIZE);
vector b(SIZE);
vector y(SIZE);
vector ans(SIZE);
matrix A_CSR(A,SIZE);
//Multiply the inputted x to generate b, then retrieve it with LU
A_CSR.times(x,b);
cout << "b = " << '\n';
b.display();
//Run LU factorization
forward(y,b,L_CSR);
backward(ans,y,U_CSR);
//Output the answer and what x was originally
cout << '\n' <<"X = ";
x.display();
cout << '\n' << "You got = ";
ans.display();
for(int i = 0; i < SIZE; ++i)
{
delete A[i];
delete A2[i];
delete L[i];
delete U[i];
}
delete [] A;
delete [] A2;
delete [] L;
delete [] U;
return 0;
}