- #1
darwinharianto
- 42
- 0
Homework Statement
make a gaussian elimination in C
the one we used on matrix to find x1 x2 and x3
if the matrix is 3x3
Homework Equations
The Attempt at a Solution
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int i,j,k,n;
float A[3][4]={{3,0,6,1},{4,1,3,2},{6,3,0,3}};
float x[3],c,sum=0;
n=2;
for(i=0; i<=n; i++);
{
for(j=0; j<=n+1; j++);
{
if(i>j);
{
c=A[i][j]/A[j][j];
for(k=0; k<=n+1; k++);
{
A[i][k]=A[i][k]-A[j][k]*c;
}
}
}
}
x[n]=A[n][n+1]/A[n][n];
for(i=n-1; i>=0; i--);
{
sum=0;
for(j=i+1; j<=n; j++);
{
sum=sum+A[i][j]*x[j];
}
x[i]=(A[i][n+1]-sum)/A[i][i];
}
printf("\nThe solution is: \n");
for(i=0; i<=n; i++);
{
printf("\nx%d=%f\t",i,x[i]);
}
return(0);
}
should be x0 x1 and x2 right?
and the result
x0=-784.191895
x1=0.000000
seems to be incorrect
anything that i did wrong?
thx for reply[/I][/I][/I][/I][/I][/I][/I][/I][/I]
Last edited: