forked from 1chipML/1chipML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gauss_elimination.c
60 lines (50 loc) · 1.48 KB
/
test_gauss_elimination.c
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
/* ************************************************* *
* Author : Jean Michel Sellier *
* Created : 08 Feb 2022, Montreal, QC, Canada *
* Last modified : 31 May 2022, Montreal, QC, Canada *
* ************************************************* */
#include "../src/1chipml.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
/* Variables and pointers declarations */
int i;
int N;
gauss_real** A; //[2][2];
gauss_real* B; //[2];
gauss_real* sol; /* pointer towards the solution */
/* dynamical memory allocation */
A = (gauss_real**)malloc(4 * sizeof(gauss_real*));
for (i = 0; i < 2; i++) {
A[i] = (gauss_real*)malloc(2 * sizeof(gauss_real));
}
B = (gauss_real*)malloc(2 * sizeof(gauss_real));
/* The following parameters define a system of 2 linear equations A*X=B */
N = 2;
A[0][0] = +1.;
A[0][1] = +1.;
A[1][0] = +1.;
A[1][1] = -1.;
B[0] = 0.;
B[1] = 1.;
/* Apply gauss elimination method to solve the system */
sol = gauss_elimination(N, A, B);
/* free memory */
for (i = 0; i < 2; i++)
free(A[i]);
free(A);
free(B);
const gauss_real expectedResults[] = {0.5, -0.5};
/* Print solution on screen */
for (i = 0; i < N; i++) {
if (sol[i] != expectedResults[i]) {
printf("Error! , %0.3f expected to be equal to %0.3f \n", sol[i],
expectedResults[i]);
return 1;
}
}
printf("Success : gauss elimination test \n");
return 0;
}
/* -- End of file -- */