Applied Gauss Seidal method to solve following system of equation up to given no. of iterations.
(1) 4x+y-z=7
(2) 2x+3y+z=4
(3) x+y-2z=2
#include<conio.h>
#include<stdio.h>
void main()
{
float x,y,z,a,b,c;
int i,n;
clrscr();
printf("enter no of iteration n");
scanf("%d",&n);
x=0;
y=0;
z=0;
a=(7-y+z)/4;
b=(4-(2*a)-z)/3;
c=((-1)*(2-a-b))/2;
printf("x y z");
printf("\n%f %f %f",a,b,c);
x=a;
y=b;
z=c;
for(i=1;i<n;i++)
{
x=(7-y+z)/4;
y=(4-(2*x)-z)/3;
z=(-1)*(2-x-y)/2;
printf("\n%f %f %f ",x,y,z);
}
getch();
}
(1) 4x+y-z=7
(2) 2x+3y+z=4
(3) x+y-2z=2
#include<conio.h>
#include<stdio.h>
void main()
{
float x,y,z,a,b,c;
int i,n;
clrscr();
printf("enter no of iteration n");
scanf("%d",&n);
x=0;
y=0;
z=0;
a=(7-y+z)/4;
b=(4-(2*a)-z)/3;
c=((-1)*(2-a-b))/2;
printf("x y z");
printf("\n%f %f %f",a,b,c);
x=a;
y=b;
z=c;
for(i=1;i<n;i++)
{
x=(7-y+z)/4;
y=(4-(2*x)-z)/3;
z=(-1)*(2-x-y)/2;
printf("\n%f %f %f ",x,y,z);
}
getch();
}
No comments:
Post a Comment