Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Gauss Seidel.c

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

File: /home/pc-122/ARPAN/Gauss_Seidel.

c Page 1 of 2

/* GAUSS SEIDEL METHOD


PROGRAM NO. 8

Problem: Solve the boundary value problem uxx + uyy = 4x - 2y in square whose vertices are
at the points (0,0),(1,0),(1,10,(0,1) with boundary conditions u(x,0) = 2x; 0<=x<=1, u(x,
1) = 2x-1; 0<=x<=1, u(0,y) + ux|(x=0) = 2-y; 0<=y<=1, u(1-y) = 2-y; 0<=y<=1.

NAME: ARPAN DATTA


ROLL NO: 002120602002 */

#include<stdio.h>
#include<math.h>
int main()
{
int i,j,s,l=0,k,h;
float o,e,n,m,x[20],y[20],u1[200][200],u[200][200],min=1;
o=0;
e=1;
h=10;
k=10;
m=(e-o)/h;
n=(e-o)/k;
// assume the initial condition
for(i=0;i<=h;i++)
{
for(j=0;j<=k;j++)
u[i][j]=0;
}
x[0]=o;
y[0]=o;
for(i=1;i<=h;i++)
x[i]=m*i;
for(i=1;i<=k;i++)
y[i]=n*i;
for(i=0;i<=h;i++)
{
u[i][0]=2*x[i];
u[i][k]=2*x[i]-1;
}
for(i=0;i<=h;i++)
u[h][i]=2-y[i];
do
{
for(i=1;i<h;i++)
{
for(j=1;j<k;j++)
{
u[0][j]=(((2-y[j])*h)-u[1][j])/(h-1);
u1[i][j]=(u[i+1][j]+u[i-1][j]+u[i][j-1]+u[i]
[j+1])/4;
if(min>fabs(u1[i][j]-u[i][j]))
min=fabs(u1[i][j]-u[i][j]);
u[i][j]=u1[i][j];
}
}
}while(min>0.00001);
printf("The solution is \n");
for(i=0;i<=h;i++)
{
for(j=0;j<=k;j++)
{
printf("u(%d,%d)=%4.3f\t",i,j,u[i][j]);
}
printf("\n\n");
}
}
File: /home/pc-122/ARPAN/Gauss_Seidel.c Page 2 of 2

/* OUTPUT
The solution is
u(0,0)=0.000 u(0,1)=1.988 u(0,2)=1.847 u(0,3)=1.730 u(0,4)=1.622
u(0,5)=1.520 u(0,6)=1.422 u(0,7)=1.330 u(0,8)=1.247 u(0,9)=1.188
u(0,10)=-1.000

u(1,0)=0.200 u(1,1)=1.111 u(1,2)=1.381 u(1,3)=1.434 u(1,4)=1.399


u(1,5)=1.318 u(1,6)=1.199 u(1,7)=1.034 u(1,8)=0.781 u(1,9)=0.311
u(1,10)=-0.800

u(2,0)=0.400 u(2,1)=0.877 u(2,2)=1.131 u(2,3)=1.226 u(2,4)=1.223


u(2,5)=1.152 u(2,6)=1.023 u(2,7)=0.826 u(2,8)=0.531 u(2,9)=0.077
u(2,10)=-0.600

u(3,0)=0.600 u(3,1)=0.865 u(3,2)=1.040 u(3,3)=1.117 u(3,4)=1.114


u(3,5)=1.045 u(3,6)=0.914 u(3,7)=0.717 u(3,8)=0.440 u(3,9)=0.066
u(3,10)=-0.400

u(4,0)=0.800 u(4,1)=0.945 u(4,2)=1.047 u(4,3)=1.089 u(4,4)=1.072


u(4,5)=0.999 u(4,6)=0.872 u(4,7)=0.689 u(4,8)=0.447 u(4,9)=0.145
u(4,10)=-0.200

u(5,0)=1.000 u(5,1)=1.068 u(5,2)=1.113 u(5,3)=1.120 u(5,4)=1.085


u(5,5)=1.007 u(5,6)=0.886 u(5,7)=0.721 u(5,8)=0.513 u(5,9)=0.269
u(5,10)=0.000

u(6,0)=1.200 u(6,1)=1.216 u(6,2)=1.217 u(6,3)=1.195 u(6,4)=1.143


u(6,5)=1.059 u(6,6)=0.943 u(6,7)=0.795 u(6,8)=0.617 u(6,9)=0.416
u(6,10)=0.200

u(7,0)=1.400 u(7,1)=1.377 u(7,2)=1.345 u(7,3)=1.299 u(7,4)=1.232


u(7,5)=1.143 u(7,6)=1.032 u(7,7)=0.899 u(7,8)=0.746 u(7,9)=0.577
u(7,10)=0.400

u(8,0)=1.600 u(8,1)=1.547 u(8,2)=1.489 u(8,3)=1.422 u(8,4)=1.343


u(8,5)=1.250 u(8,6)=1.143 u(8,7)=1.022 u(8,8)=0.889 u(8,9)=0.747
u(8,10)=0.600

u(9,0)=1.800 u(9,1)=1.722 u(9,2)=1.642 u(9,3)=1.558 u(9,4)=1.468


u(9,5)=1.372 u(9,6)=1.268 u(9,7)=1.158 u(9,8)=1.043 u(9,9)=0.922
u(9,10)=0.800

u(10,0)=2.000 u(10,1)=1.900 u(10,2)=1.800 u(10,3)=1.700 u(10,4)=1.600


u(10,5)=1.500 u(10,6)=1.400 u(10,7)=1.300 u(10,8)=1.200 u(10,9)=1.100
u(10,10)=1.000
*/

You might also like