Gauss-Jacobi Method using C



Sumit Kar, Numerical Methods, C, Timus Rak



/*


Gauss-Jacobi Method


Equation:8x+2y-2z=0,x-8y+3y=-4,2x+y+9z=12
*/
#include<conio.h>
#include<stdio.h>
void main()
{
float ax,ay,az,x,y,z;
int i,n;
float f1(float,float);
float f2(float,float);
float f3(float,float);
clrscr();
printf("\nEnter the number of equations:: ");
scanf("%d",&n);
x=y=z=0;
for(i=0;i<=n;i++)
{
ax=f1(y,z);
ay=f2(z,x);
az=f3(x,y);
x=ax;
y=ay;
z=az;
}
printf("\nx= %f, y= %f, z= %f",x,y,z);
getch();
}
float f1(float y,float z)
{
return (8-2*y+2*z)/8;
}
float f2(float z,float x)
{
return (4+x+3*z)/8;
}
float f3(float x,float y)
{
return (12-2*x-y)/9;
}


0 Comments