Personel Information

BSc: Physics Department, Middle East Technical University (METU), Ankara, Turkey
MSc: Physics Department, METU
PhD: Qualified, Physics Department, METU


Monday, July 11, 2016

JACOBI AND GAUSS-SIEDEL SCHEMES


##The formulas and the iteration procedure
##below are taken from the Devies Book
##Eqn 5.89
##Constants and Initializations
dx=1E-3; ##Increment in x.
c1=1-2.5*dx; ## c1,c2,c3,c4 are constants in Eqn.5.89
c2=1+2.5*dx;
c3=-10*dx*dx;
c4=1/(2+c3);
## Set up the initial profile
x=0.0:0.01:1.0;
yold=0:100;
hold on
plot(x,yold);
xlabel('x');
ylabel('y');
##Impose the boundary conditions
Nsteps=1000;
yoldJac=yold; ## old y values for Jacobi Iteration Scheme
yoldGauSied=yold; ## old y values for Gauss-Siedel Scheme
ynewJac=yoldJac; ## new y values for Jacobi Iteration Scheme
ynewGauSied=yoldGauSied; ## new y values for Gauss-Siedel Scheme
for n=1:Nsteps
for i=2:100
ynewJac(i)=c4*(c1*yoldJac(i+1)+c2*yoldJac(i-1)+c3*x(i));
ynewGauSied(i)=c4*(c1*yoldGauSied(i+1)+c2*ynewGauSied(i-1)+c3*x(i));
endfor
yoldJac=ynewJac;
yoldGauSied=ynewGauSied;
endfor
plot(x,ynewJac,'g*',x,ynewGauSied,'m@');
title('y vs x');
xlabel('x');
ylabel('y');
legend('y(initial)','Jacobi','Gauss-Siedel');
axis([0,1.5]);
hold off
save -text JACOBIGAUSSSIEDEL.dat
print ('-dpsc','JACOBIGAUSSSIEDEL.ps')

No comments:

Post a Comment