c-intro: example-lin.c
File example-lin.c, 521 bytes (added by , 15 years ago) |
---|
Line | |
---|---|
1 | /* M*u=b */ |
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | #include "lupack.h" |
5 | |
6 | #define N 5 |
7 | |
8 | float M[N*N]={2, 3, 0, 0, 0, |
9 | 3, 0, 4, 0, 6, |
10 | 0, -1, -3, 2, 0, |
11 | 0, 0, 1, 0, 0, |
12 | 0, 4, 2, 0, 1}; |
13 | |
14 | float b[N]={8, 45, -3, 3, 19}; |
15 | |
16 | int main() |
17 | { |
18 | int i; |
19 | int *indx; |
20 | float d; |
21 | |
22 | indx=(int *)malloc(N*sizeof(int)); |
23 | ludcmp(M, N, indx, &d); |
24 | lubksb(M, N, indx, b); |
25 | free(indx); |
26 | |
27 | for(i=0;i<N;i++) |
28 | { |
29 | printf("u[%d]= %g\n", i, b [i]); |
30 | } |
31 | return 0; |
32 | } |