Skip to content

Commit c098452

Browse files
committed
Change LU_factorisation to accept array size from user and then perform a LU_decomposition
1 parent 0da0af4 commit c098452

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

LU_factorisation

17.2 KB
Binary file not shown.

src/LU_factorisation.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ void l_u_d(float** a, float** l, float** u, int size)
6060
omp_destroy_lock(&lock);
6161
}
6262
int main(int argc, char *argv[]) {
63-
int size = 2;
63+
int size;
64+
cout<<"Please Enter size"<<endl;
65+
cin>>size;//accept the size of the array
6466
float **a, **l, **u;
6567

6668
// Allocate memory for the 2D arrays
@@ -74,16 +76,16 @@ int main(int argc, char *argv[]) {
7476
}
7577

7678
// Initialize the array 'a'
77-
float temp[2][2] = {
78-
{4, 3},
79-
{6, 3}
80-
};
79+
//Instead of manuall setting the value of an array we allow the user to input array values
80+
cout << "Enter the elements of the matrix A:" << endl;
8181
for (int i = 0; i < size; i++) {
82-
for (int j = 0; j < size; j++) {
83-
a[i][j] = temp[i][j];
84-
}
82+
for (int j = 0; j < size; j++) {
83+
cin >> a[i][j];
84+
}
8585
}
8686

87+
88+
8789
// Perform LU decomposition
8890
l_u_d(a, l, u, size);
8991

@@ -104,6 +106,15 @@ int main(int argc, char *argv[]) {
104106
}
105107
printf("\n");
106108
}
109+
//Free the dynamicall allocated memory
110+
for (int i = 0; i < size; i++) {
111+
free(a[i]);
112+
free(l[i]);
113+
free(u[i]);
114+
}
115+
free(a);
116+
free(l);
117+
free(u);
107118

108119
return 0;
109120
}

0 commit comments

Comments
 (0)