-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solvelinear.c
69 lines (68 loc) · 986 Bytes
/
Solvelinear.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
61
62
63
64
65
66
67
68
69
#include<stdio.h>
#include<stdlib.h>
float* Solveliner(int n, float A[][n+1], float x[])//Using Gauss Jorden Method
{
int i, j, k, e, l, m;
if(n<=0)
{
if(n==0)
n=-1;
n=n*-1;
}
printf("\nMatrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<=n;j++)
{
printf("%.4f\t\t",A[i][j]);
}
printf("\n");
}
float r;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(j==i)
continue;
if(A[i][i]==0)
{
for(e=0;e<n;e++)
{
if(A[e][i]!=0)
{
for(k=0;k<=n;k++)
A[i][k]+=A[e][k];
}
}
}
r=A[j][i]/A[i][i];
for(k=0;k<=n;k++)
A[j][k]=A[j][k]-r*A[i][k];
}
printf("\nMatrix in step %d\n",i+1);
for(l=0;l<n;l++)
{
for(m=0;m<=n;m++)
{
printf("%.4f\t\t",A[l][m]);
}
printf("\n");
}
}
printf("\nDiagnoal Matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<=n;j++)
{
printf("%.4f\t\t",A[i][j]);
}
printf("\n");
}
float sum;
for(i=0;i<n;i++)
{
x[i]=A[i][n]/A[i][i];
}
return x;
}