# PROGRAM ON ROOTS OF EQUATION:-NEWTON RAPHSON METHOD

function raphson
clc;
clear;
s=input('\n ENTER F(x)=','s');
f=inline(s);
s=input('\n ENTER dF(x)=','s');
df=inline(s);
x=input('\n ENTER INITIAL GUESS:');
n=100;
acc=input('\n ENTER ACCURACY:');
fprintf('\n
x
f(x)');
for i=1:1:n
x=x-f(x)/df(x);
fprintf('\n %f
%f',x,f(x));
if(abs(f(x))<acc)
fprintf('\n ROOT=%f',x);
break;
end
end
if(i>=n)
fprintf('\n ROOT WILL NOT CONVERGE WITH GIVEN GUESS');
end
end

OUTPUT
ENTER F(x)=-(h^3)+9*(h^2)-(90/pi)
ENTER dF(x)=-3*(h^2)+18*h
ENTER INITIAL GUESS:2
ENTER ACCURACY:0.000001
x

f(x)

2.026995

0.002167

2.026906

0.000000

ROOT=2.026906>>

PROGRAM ON ROOTS OF EQUATION:-NEWTON MODIFIED RAPHSON
function raphsonmodified
clc;
clear;
s=input('\n ENTER F(x)=','s');
f=inline(s);
s=input('\n ENTER dF(x)=','s');
df=inline(s);
x=input('\n ENTER INITIAL GUESS:');
df=df(x);
n=100;
acc=input('\n ENTER ACCURACY:');
fprintf('\n
x
f(x)');
for i=1:1:n
x=x-f(x)/df;
fprintf('\n %f
%f',x,f(x));
if(abs(f(x))<acc)
fprintf('\n ROOT=%f',x);
break;
end
end
if(i>=n)
fprintf('\n ROOT WILL NOT CONVERGE WITH GIVEN GUESS');
end
end

026906>> .026905 -0.000000 ROOT=2.026995 0.000014 2.026906 0.OUTPUT ENTER F(x)=-(h^3)+9*(h^2)-(90/pi) ENTER dF(x)=-3*(h^2)+18*h ENTER INITIAL GUESS:2 ENTER ACCURACY:0.002167 2.000001 x f(x) 2.

x. g=inline(s). n=input('\n ENTER NUMBER OF ITERATIONS TO BE PERFORMED').x). end end end . x=g(x). fprintf(' %f %f'.'s').x). fprintf('\n x g(x) f(x)').f(x)). if(abs(f(x))<acc) fprintf('\n ROOT OF EQUATION%f'. s=input('\n ENTER g(x):'. acc=input('\n ENTER ACCRACY:'). x=input('\n ENTER INITIAL GUESS:'). f=inline(s).'s'). if(i>=n) fprintf('\n ROOT DOES NOT CONVERGE IN GIVEN ITERATIONS'). clear. while(i<=n) fprintf('\n %f'. s=input('\n ENTER f(x):'. i=1. break.PROGRAM ON ROOTS OF EQUATION:-FIXED POINT ITERATION function fixediteration clc. end i=i+1.

026561 2.026906 -0.026906 2.025885 2.002813 2.000037 2.023880 2.024658 2.026789 2.026892 -0.026905 -0.000000 2.008327 2.026866 2.000001 2.026906>> .026906 -0.017917 2.026904 -0.000108 2.000000 ROOT OF EQUATION2.000012 2.OUTPUT ENTER g(x):(sqrt((h^3)+(90/pi)))/3 ENTER f(x):-(h^3)+9*(h^2)-(90/pi) ENTER INITIAL GUESS:2 ENTER NUMBER OF ITERATIONS TO BE PERFORMED100 ENTER ACCURACY:0.000321 2.023880 -0.026561 -0.216932 2.073066 2.026904 2.026901 -0.026892 2.026901 2.000004 2.026906 -0.000001 x g(x) f(x) 2.025885 -0.026906 2.000950 2.026789 -0.026866 -0.026905 2.017917 -0.

sum).'s'). fprintf('\n Integration=%f'. x0=input('\n ENTER INITIAL VALUE:'). end . h=(xN-x0)/n. x0=x0+2*h. clear. f=inline(s).PROGRAM ON NUMERICAL INTEGRATION:-SIMPSONS 1/3rd RULE function simpson1 clc. s=input('\n ENTER THE FUNCTION:'. n=2*m. xN=input('\n ENTER FINAL VALUE:'). end sum=sum*(h/3). sum=0. for i=1:1:m sum=sum+f(x0)+4*f(x0+h)+f(x0+2*h). m=input('\n ENTER NUMBER OF MAJOR STRIPS:').

OUTPUT
ENTER THE FUNCTION:5+0.25*x^2
ENTER NUMBER OF MAJOR STRIPS:10
ENTER INITIAL VALUE:0
ENTER FINAL VALUE:11
Integration=165.916667>>

PROGRAM ON NUMERICAL INTEGRATION:-SIMPSONS 3/8th RULE
function simpson3
clc;
clear;
s=input('\n ENTER THE FUNCTION:','s');
f=inline(s);
m=input('\n ENTER NUMBER OF MAJOR STRIPS:');
n=3*m;
sum=0;
x0=input('\n ENTER INITIAL VALUE:');
xN=input('\n ENTER FINAL VALUE:');
h=(xN-x0)/n;
for i=1:1:m
sum=sum+f(x0)+3*f(x0+h)+3*f(x0+2*h)+f(x0+3*h);
x0=x0+3*h;
end
sum=sum*(3*h/8);
fprintf('\n Integration=%f',sum);
end

OUTPUT
ENTER THE FUNCTION:5+0.25*x^2
ENTER NUMBER OF MAJOR STRIPS:9
ENTER INITIAL VALUE:0
ENTER FINAL VALUE:11
Integration=165.916667>>

sum=0. fprintf('\n Integration=%f'.'s'). f=inline(s). end . clear. m=input('\n ENTER NUMBER OF MAJOR STRIPS:'). h=(xN-x0)/n. x0=x0+h. for i=1:1:m sum=sum+f(x0)+f(x0+h). xN=input('\n ENTER FINAL VALUE:').PROGRAM ON NUMERICL INTEGRATION:-TRAPEZOIDAL RULE function trapezoidal clc. x0=input('\n ENTER INITIAL VALUE:').sum). s=input('\n ENTER THE FUNCTION:'. n=m. end sum=sum*(h/2).

375000>> .OUTPUT ENTER THE FUNCTION:5+0.25*x^2 ENTER NUMBER OF MAJOR STRIPS:11 ENTER INITIAL VALUE:0 ENTER FINAL VALUE:11 Integration=166.

area). end . xn=input('\n ETER FINAL LIMIT:'). b=(xn+x0)/2. x0=input('\n ENTER INITIAL LIMIT:'). clear. x2=a*1/(sqrt(3))+b. area=a*(f(x1)+f(x2)).'s'). fprintf('\n area =%f '. s=input('\n ENTER FUNCTION:'. f=inline(s). x1=-a*1/(sqrt(3))+b.PROGRAM ON NUMERICAL INTEGRATION:-GAUSS QUADRATURE 2POINT METHOD function twopointgauss clc. a=(xn-x0)/2.

OUTPUT ENTER FUNCTION:5+0.25*x^2 ENTER INITIAL LIMIT:0 ETER FINAL LIMIT:11 area =165.916667 >> .

a=(xn-x0)/2.'s').area). s=input('\n ENTER FUNCTION:'. f=inline(s). area=(a*(5*f(x1)+8*f(x2)+5*f(x3)))/9. x3=a*(sqrt(3/5))+b.PROGRAM ON NUMERICAL INTEGRATION:-GAUSS QUADRATURE 3POINT METHOD function threepointgauss clc. b=(xn+x0)/2. x2=b. clear. fprintf('\n area =%f '. x0=input('\n ENTER INITIAL LIMIT:'). end . xn=input('\n ETER FINAL LIMIT:'). x1=-a*(sqrt(3/5))+b.

25*x^2 ENTER INITIAL LIMIT:0 ETER FINAL LIMIT:11 area =165.916667 >> .OUTPUT ENTER FUNCTION:5+0.

xx]=readdata. for i=1:1:n x(i)=input('\n x='). end function yy=interpolate(x. end end yy=yy+sum*y(i).PROGRAM ON INTERPOLATION:-LAGRANGES METHOD function lagranges clc. for j=1:1:n if(i~=j) sum=sum*(xx-x(j))/(x(i)-x(j)).y.xx) n=length(x). end end . end xx=input('\n xx='). for i=1:1:n sum=1. [x. clear. yy=interpolate(x.y.xx]=readdata n=input('\n ENTER NUMBER OF DATA:').yy). y(i)=input(' y=').y. fprintf('\n y(%f)=%f'.y.xx). yy=0. end function [x.xx.

500000)=37.5 y(2.OUTPUT ENTER NUMBER OF DATA:5 x=1 y=10 x=2 y=26 x=3 y=50 x=4 y=82 x=5 y=122 xx=2.000000>> .

yy).j)).xx. for(i=2:1:n) sumu=sum*u. yy=interpolate(x. y(i. for(i=1:1:n) x(i. end function [x.i)*sumu/fact. yy=y(1. sum=1.y.y) n=length(x). end end .1). sum=sumu. fact=1.y.y).1)=input('y:').y). fact=fact*i. n=length(x). end end end function [yy]=interpolate(x.xx) u=(xx-x(1))/(x(2)-x(1)). display(x.y. y=fdtable(x. for(i=1:1:n) fprintf('\n %f'.y.j)=y(i+1. end function [y]=fdtable(x.xx]=readdata n=input('\n Enter number of data to be entered:'). for(j=2:1:n) for(i=1:1:n-(j-1)) y(i. u=u-1.j-1)-y(i.PROGRAM ON INTERPOLATION:-NEWTONS FORWARD DIFFERENCE function NFD clc. [x.x(i)).xx). end xx=input('\n ENTER XX:'). end end end function display(x.y) n=length(x).xx]=readdata. yy=yy+y(1.j-1).y(i. fprintf('\n y(%f)=%f'.1)=input('\n x:'). for(j=1:1:n) fprintf('\t %f'. clear.

000000 8.000000 0.5 1.000000 4.000000 8.000000 2.000000 82.000000 0.000000 0.000000 0.000000 y(2.000000 0.000000 0.000000 16.000000 50.000000>> .000000 8.000000 40.000000 24.000000 0.000000 0.000000 0.000000 0.000000 0.500000)=37.OUTPUT Enter number of data to be entered:5 x:1 y:10 x:2 y:26 x:3 y:50 x:4 y:82 x:5 y:122 ENTER XX:2.000000 5.000000 26.000000 0.000000 3.000000 0.000000 32.000000 10.000000 122.

PROGRAM ON INTERPOLATION:-NEWTONS BACKWARD DIFFERENCE function nbd clc.y).x(i)). end xx=input('\n enter x at which y is required:'). u=u+1. y(i.j)).j)=y(i.j-1). end end end function yy=interpolate(x.xx]=readdata.1).i). fprintf('\n\n y(%f)=%f'.xx) n=length(x). yy=yy+y(n. yy=y(n.y. display(x. x(i)=input('').y. clear. end function [x. [x. for j=2:1:n for i=n:-1:j y(i.1)=input('').yy). end end end function display(x. fact=fact*i. for i=2:1:n sumu=sumu*u. end function y=bdtable(x.y) n=length(x).xx.xx]=readdata n=input('\n enter number of data:').i)*sumu/fact. for i=1:1:n fprintf('\n %f'.j-1)-y(i-1.y).y.i). for i=1:1:n fprintf('\n x%d='. sumu=1. for j=1:1:n fprintf('\t %f'. yy=interpolate(x. u=(xx-x(n))/(x(2)-x(1)).xx). fprintf('y%d='.y.y(i.y) n=length(x). fact=1. y=bdtable(x. end end .

000000 8.000000 40.000000 50.000000 0.000000 8.000000 0.000000 4.000000 82.000000>> .500000)=37.5 1.000000 0.000000 0.000000 0.000000 2.000000 5.000000 0.000000 0.000000 0.000000 32.000000 0.000000 122.000000 0.000000 16.000000 3.000000 0.000000 0.000000 y(2.000000 26.000000 8.000000 24.OUTPUT enter number of data:5 x1=1 y1=10 x2=2 y2=26 x3=3 y3=50 x4=4 y4=82 x5=5 y5=122 enter x at which y is required:2.000000 0.000000 10.

s=1. fprintf('\n At x=%f dy/dx=%f'.y.j)=NFD(i+1.x(i)). [x. for j=1:1:n-1 dxy=dxy+s*NFD(1.y]=readdata. h=x(2)-x(1). of points:').j)=y(i+1)-y(i).y]=readdata n=input('\n ENTER No. dxy=0.dxy).j)). clear. display(x. for j=1:1:n for i=1:1:(n-j) if(j==1) NFD(i. end end end end function display(x. dxy=diff(x.NFD).y.x(1). end function [x.j-1). for i=1:1:n x(i)=input('\nx:').j)*(1/j).y. for i=1:1:n fprintf('\n %f'.NFD).NFD(i.NFD) n=length(x). for j=1:1:n-i fprintf('\t %f'. NFD=nfdtable(y). end end end function dxy=diff(x. s=s*(-1). end .y.j-1)-NFD(i. end dxy=(1/h)*dxy. y(i)=input('y:'). end end function NFD=nfdtable(y) n=length(y). else NFD(i.NFD) n=length(y).PROGRAM ON DIFFERENTIATION:-NEWTONS FORWARD DIFFERENCE function NFDDiff clc.

000000 .000000 1.000000 At x=0.000000 12.000000 7.000000 2.000000 5.000000 3.000000 4.000000 5.000000 12. of points:5 x:0 y:2 x:1 y:5 x:2 y:10 x:3 y:22 x:4 y:34 0.OUTPUT ENTER No.000000 3.000000 -7.000000 dy/dx=6.666667>> -12.000000 2.000000 0.

y. dxy=0.x(i).NBD). else NBD(i.y. end dxy=(1. y(i)=input('\n ENTER VALUE OF y:').dxy).j-1). NBD=nbdtable(y). for j=1:1:n-1 dxy=dxy+NBD(n. fprintf('\n At x=%f dy/dx=%f'.y]=readdata.j)=NBD(i.0/h)*dxy.NBD) n=length(x). of points:').y. if(i~=1) for j=1:1:i-1 fprintf('\t %f'. clear.NBD). end function [x.j)). end end function NBD=nbdtable(y) n=length(y).y. end end function dxy=diff(x.NBD) n=length(y).NBD(i. dxy=diff(x. end end fprintf('\n '). for i=1:1:n x(i)=input('\n ENTER VALUE OF x:'). for i=1:1:n fprintf('\n %f %f'.x(n). for j=1:1:n-1 for i=n:-1:j+1 if(j==1) NBD(i. h=x(2)-x(1).y(i)).j)=y(i)-y(i-1). [x. display(x. end .j)*(1/j).PROGRAM ON DIFFERENTIATION:-NEWTONS BACKWARD DIFFERENCE function NBDDiff clc.y]=readdata n=input('\n ENTER No.j-1)-NBD(i-1. end end end end function display(x.

000000 16.000000 4.000000 5.OUTPUT ENTER No.000000>> 0.000000 2.000000 2.000000 3.000000 3.000000 At x=4.000000 2.000000 9.000000 1.000000 dy/dx=8.000000 4. of points:4 ENTER VALUE OF x:1 ENTER VALUE OF y:1 ENTER VALUE OF x:2 ENTER VALUE OF y:4 ENTER VALUE OF x:3 ENTER VALUE OF y:9 ENTER VALUE OF x:4 ENTER VALUE OF y:16 1.000000 7.000000 .

end c(k)=c(k)-temp*c(i).x(4)). (3*x1^2) (2*x1) 1 0]. x1^3 x1^2 x1 1. y0=input('\n ENTER y of first point:'). c=[y0 y1 yd0 yd1]. c(i)=c(k). for j=1:1:n a(k.j)=temp.j)-temp*a(i. x=gausselimination(a. a=[x0^3 x0^2 x0 1. end end end end % UPPER TRIANGULAR FORM function [a.yr).c).x(1).j)=a(k. end function x=gausselimination(a.c]=pivote(a.j). yr=(x(1)*xr^3)+(x(2)*xr^2)+(x(3)*xr)+x(4). y1=input('\n ENTER y of second point:').c) n=length(c).c). clear. a(i. end function [a. xr=input('\n ENTER x for which y is to be determined:').c]=pivote(a.c) n=length(c). end end end . x1=input('\n ENTER x of second point:').i))<abs(a(k. x0=input('\n ENTER x of first point:'). fprintf('\n y=%fx^3+%fx^2+%fx+%f'.xr.c).j). for i=1:1:n-1 for k=i+1:1:n if(abs(a(i.c]=upper(a. c(k)=temp. yd0=input('\n ENTER yd of first point:').c).(3*x0^2) (2*x0) 1 0.x(2).i)/a(i.j). fprintf('at x=%f y is %f'. [x]=back(a. a(k. yd1=input('\n ENTER yd of second point:'). for i=1:1:n-1 for k=i+1:1:n temp=a(k.i))) for j=1:1:n temp=a(i.c) a c [a.i). [a.j)=a(k.x(3).PROGRAM ON INTERPOLATION:-HERMITE INTERPOLATION function hermiteinter clc. end temp=c(i).c]=upper(a.

for j=i+1:1:n temp=temp-a(i. end end .i).c) n=length(c).% BACK SUBSTITUTION function [x]=back(a.j)*x(j). for i=n:-1:1 temp=c(i). end x(i)=temp/a(i.

0000 1.69315 ENTER yd of first point:0.0000 1.6932 0.4000 y=0.OUTPUT ENTER x of first point:2 ENTER y of first point:0.029760x^3+-0.91629 ENTER yd of second point:.9163 0.0000 4.0000 12.300880x^2+1.034210 ENTER x for which y is to be determined:2.0000 2.7500 5.0000 0 18.6250 6.200000 y is 0.346400x+-1.2 at x=2.0000 4.788495>> .5000 0.0000 0 c= 0.0000 1.0000 15.5 ENTER x of second point:2.5 ENTER y of second point:0.4 a= 8.2500 2.5000 1.

i).j). c(i)=c(k). end end % PIVOTING function [a.c]=upper(a.c]=upper(a. x end % READ DATA function [a.j)=input(' '). end j=1.c) n=length(c).c]=readdata.i)/a(i. end temp=c(i). a c x=back(a.PROGRAM ON SIMULTANEOUS EQUATIONS:-GAUSS ELIMINATION METHOD function x=GaussElimination clc.i. for j=1:1:n . for i=1:1:n-1 for k=i+1:1:n if(abs(a(i. a(i. clear.i))<abs(a(k. c(i. for i=1:1:n-1 for k=i+1:1:n temp=a(k.j).c]=readdata n=input('\n Enter number of Equations').c).c]=pivote(a.i))) for j=1:1:n temp=a(i. a(k. fprintf('c[%d][%d]= '.j)=input(' ').c).c). c(k)=temp.j)=temp. [a.j). a c [a. a c [a.j)=a(k.j). for i=1:1:n for j=1:1:n fprintf('a[%d][%d]= '. end end end end % UPPER TRIANGULAR FORM function [a.c) n=length(c). a(i.c]=pivote(a.i.

c) n=length(c).i). end c(k)=c(k)-temp*c(i). end x(i)=temp/a(i.j)*x(j). end end end % BACK SUBSTITUTION function [x]=back(a.j)=a(k. for i=n:-1:1 temp=c(i). for j=i+1:1:n temp=temp-a(i.a(k.j).j)-temp*a(i. end end .

OUTPUT Enter number of Equations3 a[1][1]= 130 a[1][2]= -30 a[1][3]= 0 c[1][1]= 500 a[2][1]= 1 a[2][2]= -1 a[2][3]= 0 c[2][1]= 0 a[3][1]= 40 a[3][2]= 60 a[3][3]= -120 c[3][1]= -200 a= 130 -30 1 -1 0 0 40 60 -120 c= 500 0 -200 a= 130 -30 0 40 60 -120 .

7778 x = 5.0000 -353.0000 5.0000 -30.0000 0 0 69.8333>> .1 -1 0 c= 500 -200 0 a= 130.8462 -7.3333 c= 500.2308 -120.0000 0 0 -1.0000 5.

clear. xn=input('\n final value of x='). x1=x1+h. h=input('\n increment in x='). y1=input('\n enter initial y value=').y1).PROGRAM ON ORDINARY DIFFERENTIAL EQUATION:-EULERS METHOD function euler clc. x1=input('\n enter initial x value='). fprintf('X Y').x1. s=input('\n enter function:'.y1). f=inline(s).'s'). while(x1<xn) y1=y1+h*f(x1. fprintf('\n%f %f\n'. end end .

500000 3.400000 3.200000 2.511800 0.008200 0.300000 3.1 enter function:-2*x^3+12*x^2-20*x+8.100000 1.OUTPUT enter initial x value=0 enter initial y value=1 final value of x=.5 increment in x=0.360800 0.5+0*y X Y 0.590000 >> .850000 0.

y1). x2=x1+h. while(x1<=xn) yp=y1+h*f(x1.'s').y1).yp))/2. y1=input('\n enter initial y value=').x1. acc=input('\n ENTER REQUIRED ACCURACY'). s=input('\n enter function:'. fprintf('X Y'). yc=y1+h*(f(x1. while(abs(yc-yp)>acc) yp=yc. y1=yc. h=input('\n increment in x='). end fprintf('\n%f %f'. end end .PROGRAM ON ORDINARY DIFFERENTIAL EQUATION:-MODIFIED EULER function eulermod clc. clear. yc=y1+h*(f(x1. xn=input('\n final value of x=').y1)+f(x2.y1)+f(x2. f=inline(s). x1=x2. x1=input('\n enter initial x value=').yp))/2.

806726 0.000000 0.850428 0.100000 0.500000 0.000001 X Y 0.913295 0.300000 0.400000 0.000000 1.778855 0.1 enter function:X-(Y^2) ENTER REQUIRED ACCURACY0.OUTPUT enter initial x value=0 enter initial y value=1 final value of x=0.764315 >> .5 increment in x=0.200000 0.

k=(k1+k2)/2.x1. x1=x1+h. x1=input('\n ENTER INITIAL VALUE OF x='). k2=h*f(x1+h. y1=input('\n ENTER INITIAL VALUE OF y='). end end .y1).y1). h=input('\n ENTER INCREMENT OF x='). y1=y2. y2=y1+k.PROGRAM ON ORDINARY DIFFERENTIAL EQUATION:-RUNGE KUTTA 2 function runge2() clc. fprintf('\n AT x=%f y=%f \n'.'s'). f=inline(s). fprintf('\n k1=%f k2=%f'.k1. s=input('\n ENTER FUNCTION='. xn=input('\n ENTER FINAL VALUE OF x='). clear.k2). while(x1<xn) k1=h*f(x1.y1+k1).

766952 >> .1 ENTER FUNCTION=X-Y^2 k1=-0.007810 AT x=0.021056 k2=-0.914500 k1=-0.073631 k2=-0.852331 k1=-0.400000 y=0.052647 k2=-0.809033 k1=-0.500000 y=0.5 ENTER INCREMENT OF x=0.300000 y=0.071000 AT x=0.781385 k1=-0.019843 AT x=0.050706 AT x=0.OUTPUT ENTER INITIAL VALUE OF x=0 ENTER INITIAL VALUE OF y=1 ENTER FINAL VALUE OF x=0.033950 AT x=0.100000 y=0.100000 k2=-0.200000 y=0.035453 k2=-0.

k3=h*f(x1+h/2. while(x1<xn) k1=h*f(x1. k4=h*f(x1+h.y1).k2. fprintf('\n AT x=%f y=%f \n'.x1.y1+k1/2).y1+k2/2). s=input('\n ENTER FUNCTION='. k2=h*f(x1+h/2. y1=y2. end end . x1=input('\n ENTER INITIAL VALUE OF x='). k=(k1+2*k2+2*k3+k4)/6.y1+k3). xn=input('\n ENTER FINAL VALUE OF x=').y1). h=input('\n ENTER INCREMENT OF x='). f=inline(s).k1.k3.'s').k4). y1=input('\n ENTER INITIAL VALUE OF y='). y2=y1+k. x1=x1+h. clear.PROGRAM ON ORDINARY DIFFERENTIAL EQUATION:-RUNGE KUTTA 4 function runge4() clc. fprintf('\n k1=%f k2=%f k3=%f k4=%f'.

OUTPUT
ENTER INITIAL VALUE OF x=0
ENTER INITIAL VALUE OF y=1
ENTER FINAL VALUE OF x=1
ENTER INCREMENT OF x=0.5
ENTER FUNCTION=3*X+Y/2

k1=0.250000 k2=0.656250 k3=0.707031 k4=1.176758
AT x=0.500000 y=1.692220

k1=1.173055 k2=1.694687 k3=1.759891 k4=2.363028
AT x=1.000000 y=3.433093>>

PROGRAM ON SIMULTANEOUS DIFFERENTIAL EQUATION:-RUNGE
KUTTA 4 FOR 2nd ORDER
function RK4sim
clc;
clear;
s=input('\n ENTER F(x)=','s');
f=inline(s);
s=input('\n ENTER G(x)=','s');
g=inline(s);
x0=input('\n ENTER INITIAL VALUE OF x=');
y0=input('\n ENTER INITIAL VALUE OF y=');
z0=input('\n ENTER INITIAL VALUE OF z=dy/dx :');
xn=input('\n ENTER THE VALUE OF x FOR WHICH y IS TO BE DETERMINED=');
h=input('\n ENTER STEP SIZE=');
n=(xn-x0)/h;
for i=1:1:n
k1=h*f(x0,y0,z0);
l1=h*g(x0,y0,z0);
k2=h*f(x0+h/2,y0+k1/2,z0+l1/2);
l2=h*g(x0+h/2,y0+k1/2,z0+l1/2);
k3=h*f(x0+h/2,y0+k2/2,z0+l2/2);
l3=h*g(x0+h/2,y0+k2/2,z0+l2/2);
k4=h*f(x0+h,y0+k3,z0+l3);
l4=h*g(x0+h,y0+k3,z0+l3);
k=(k1+2*k2+2*k3+k4)/6;
l=(l1+2*l2+2*l3+l4)/6;
y0=y0+k;
z0=z0+l;
end
fprintf('\n VALUE OF y for x=%f is%f', xn,y0);
end

OUTPUT
ENTER F(x)=0*X+0*Y+1*Z
ENTER G(x)=-(4*Y+Z)/4+0*X
ENTER INITIAL VALUE OF x=0
ENTER INITIAL VALUE OF y=1
ENTER INITIAL VALUE OF z=dy/dx :0
ENTER THE VALUE OF x FOR WHICH y IS TO BE DETERMINED=2.5
ENTER STEP SIZE=0.5
VALUE OF y for x=2.500000 is-0.520282>>

i=i+1.y(i-1))+2*f(x(i).yp).y):'. f=inline(s). clc. end xn=input('\n ENTER VALUE OF x for y to be found=').'s').y(i-2))-f(x(i-1). i=i+2. while(x(i)<=xn) i=i-1. yc=y(i-1)+h*(f(x(i+1). h=abs(x(2)-x(1)).yp)+4*f(x(i).y(i)))/3. for i=1:1:4 x(i)=input('\n ENTER VALUE OF x='). yp=yc.y(i-1)))/3. fprintf('\n At x=%f y=%f'. fprintf('\n ENTER FIRST 4 POINTS').y(i))+f(x(i-1). x(i)=x(i-1)+h. fprintf('\n\t\typ=%f'.PROGRAM ON PREDICTOR CORRECTOR METHOD:-MILNES METHOD function milnes() clear.yc). yp=y(i-3)+4*h*(2*f(x(i-2). y(i)=input('\n ENTER VALUE OF y='). s=input('\n ENTER THE FUNCTION f(x.x(i+1). x(i)=x(i-1)+h. end end .

y):X+Y ENTER FIRST 4 POINTS ENTER VALUE OF x=0 ENTER VALUE OF y=1 ENTER VALUE OF x=0.2 ENTER VALUE OF y=1.583641>> .400000 y=1.1103 ENTER VALUE OF x=0.3997 ENTER VALUE OF x for y to be found=0.2428 ENTER VALUE OF x=0.1 ENTER VALUE OF y=1.4 yp=1.OUTPUT ENTER THE FUNCTION f(x.3 ENTER VALUE OF y=1.583627 At x=0.

while(x(i)<=xn) i=i-1. s=input('\n ENTER THE FUNCTION f(x. y(i+1)=yc. i=i+2. end end . yc=y(i)+h*(9*f(x(i+1).y(i-1))+f(x(i-2). yp=y(i)+h*(55*f(x(i). f=inline(s). clc. x(i)=x(i-1)+h. i=i+1.y(i))-5*f(x(i-1).y(i))-59*f(x(i-1).y(i-1))+37*f(x(i-2).y(i+1)). fprintf('\n\t\typ=%f'. fprintf('\n ENTER FIRST 4 POINTS').y(i-2))-9*f(x(i-3).y(i-2)))/24.yp).x(i+1). y(i)=input('\n ENTER VALUE OF y='). fprintf('\n At x=%f y=%f'.yp)+19*f(x(i).y(i-3)))/24.'s').PROGRAM ON PREDICTOR CORRECTOR METHOD:-ADAMS BASHFORTH function adamb() clear. end xn=input('\n ENTER VALUE OF x for y to be found='). for i=1:1:4 x(i)=input('\n ENTER VALUE OF x='). h=abs(x(2)-x(1)).y):'. x(i)=x(i-1)+h.

1 ENTER VALUE OF y=1.y):X+Y ENTER FIRST 4 POINTS ENTER VALUE OF x=0 ENTER VALUE OF y=1 ENTER VALUE OF x=0.583630>> .400000 y=1.2 ENTER VALUE OF y=1.OUTPUT ENTER THE FUNCTION f(x.583614 At x=0.1103 ENTER VALUE OF x=0.3997 ENTER VALUE OF x for y to be found=0.4 yp=1.2428 ENTER VALUE OF x=0.3 ENTER VALUE OF y=1.

for i=1:1:n+1 for j=1:1:m+1 a(i. y0=input('\n ENTER INITIAL LIMITS in y:'). end end for j=1:1:m area=area+s(j)+s(j+1). for j=1:1:m+1 s(j)=0. yn=input('\n ENTER FINAL LIMITS in y:'). k=(yn-y0)/m.PROGRAM ON DOUBLE INTEGRATION:-TRAPEZOIDAL METHOD function doubletrap clc. y=y0:k:yn.'s').j)=f(x(i). x=x0:h:xn. xn=input('\n ENTER FINAL LIMITS in x:'). s=input('\n ENTER FUNCTION:'.j)+a(i+1. fprintf('\n area=%f'. end end area=0. for i=1:1:n s(j)=s(j)+a(i. m=input('\n ENTER MAJOR STRIPS in y:').j). clear. n=input('\n ENTER MAJOR STRIPS in x:'). h=(xn-x0)/n.y(j)). f=inline(s). x0=input('\n ENTER INITIAL LIMITS in x:').area). . end area=h*k/4*area.

OUTPUT ENTER FUNCTION:exp(x+y) ENTER MAJOR STRIPS in x:2 ENTER MAJOR STRIPS in y:2 ENTER INITIAL LIMITS in x:0 ENTER FINAL LIMITS in x:1 ENTER INITIAL LIMITS in y:0 ENTER FINAL LIMITS in y:1 area=3.000000>> .

k=(yn-y0)/(2*m).area).PROGRAM ON DOUBLE INTEGRATION:-SIMPSONS 1/3rd RULE function doublesimp clc. fprintf('\n area=%f'.y(j)). yn=input('\n ENTER FINAL LIMITS in y:'). end area=h*k/9*area.j)+a(i+2. end end for j=1:2:2*m area=area+s(j)+4*s(j+1)+s(j+2). f=inline(s). h=(xn-x0)/(2*n). xn=input('\n ENTER FINAL LIMITS in x:'). for i=1:2:2*n s(j)=s(j)+a(i.j). end .'s'). x=x0:h:xn. for j=1:1:2*m+1 s(j)=0. y0=input('\n ENTER INITIAL LIMITS in y:'). m=input('\n ENTER MAJOR STRIPS in y:'). clear.j)=f(x(i). end end area=0. n=input('\n ENTER MAJOR STRIPS in x:'). y=y0:k:yn.j)+4*a(i+1. for i=1:1:2*n+1 for j=1:1:2*m+1 a(i. x0=input('\n ENTER INITIAL LIMITS in x:'). s=input('\n ENTER FUNCTION:'.

OUTPUT ENTER FUNCTION:exp(x+y) ENTER MAJOR STRIPS in x:2 ENTER MAJOR STRIPS in y:2 ENTER INITIAL LIMITS in x:0 ENTER FINAL LIMITS in x:1 ENTER INITIAL LIMITS in y:0 ENTER FINAL LIMITS in y:1 area=2.923611>> .

PROGRAM ON NUMERICAL INTEGRATION IN TABULAR FORMAT:SIMPSONS 1/3rd METHOD function tabsimp1 clc. end temp=0. h=x(2)-x(1). for i=1:2:n-2 temp=temp+y(i)+y(i+2)+4*y(i+1). end int=temp*h/3. for i=1:1:n x(i)=input('\n x(i)='). fprintf('\n INTEGRATION=%f'. clear. end . y(i)=input('\n y(i)=').int). n=input('\n number of data=').

333333>> .OUTPUT number of data=7 x(i)=0 y(i)=0 x(i)=2 y(i)=22 x(i)=4 y(i)=30 x(i)=6 y(i)=27 x(i)=8 y(i)=18 x(i)=10 y(i)=7 x(i)=12 y(i)=0 INTEGRATION=213.

end temp=0. for(i=1:1:n) fprintf('\n x(%d)='. fprintf('\n INTEGRATION=%f'. for(i=1:1:n-1) temp=temp+y(i)+y(i+1). clear. h=x(2)-x(1).i). end .int).i). n=input('\n NUMBER OF DATA=').PROGRAM ON NUMERICAL INTEGRATION IN TABULAR FORMAT:TRAPEZOIDAL METHOD function tabtrap clc. x(i)=input(' '). fprintf('\n y(%d)='. y(i)=input(' '). end int=temp*h/2.

37 x(8)= 16 y(8)= 83.75 x(4)= 8 y(4)= 483.06 x(3)= 6 y(3)= 416.4 x(7)= 14 y(7)= 183.OUTPUT NUMBER OF DATA=10 x(1)= 2 y(1)= 166.44 x(6)= 12 y(6)= 333.34 x(10)= 20 y(10)= 0 INTEGRATION=4900.43 x(5)= 10 y(5)= 533.7 x(2)= 4 y(2)= 300.980000>> .35 x(9)= 18 y(9)= 33.

h=x(2)-x(1).PROGRAM ON NUMERICAL INTEGRATION IN TABULAR FORMAT:SIMPSONS 3/8th METHOD function tabsimp3 clc. clear. n=input('\n number of data='). end int=temp*3*h/8.int). for i=1:3:n-3 temp=temp+y(i)+3*y(i+1)+3*y(i+2)+y(i+3). for i=1:1:n x(i)=input('\n x(i)='). end . end temp=0. y(i)=input('\n y(i)='). fprintf('\n integration =%f'.

OUTPUT number of data=7 x(i)=1 y(i)=81 x(i)=2 y(i)=75 x(i)=3 y(i)=80 x(i)=4 y(i)=83 x(i)=5 y(i)=78 x(i)=6 y(i)=70 x(i)=7 y(i)=60 integration =456.000000>> .

a(k. [a.j).r]=cha(a. c(k)=temp. x=back(a.c]=readdata n=input('\nEnter number of equations').PROGRAM ON SIMULTANEOUS EQUATION:-TDMA function x=tdma clc.q.c) n=length(c). for i=1:1:n .i))) for j=1:1:n temp=a(i.j)=a(k.c). a. a(i.c).1)=input('').c).c]=pivote(a. clear.j).c]=change(a. c.r]=cha(a.c) n=length(c).j)=input('').i))<abs(a(k. a c [a. end end end end % cha function [p. for i=1:1:n for j=1:1:n fprintf('a[%d][%d]='. end fprintf('c[%d]='.c).j).c]=pivote(a. p q r [a. end temp=c(i).q. end end % PIVOTING function [a. c(i)=c(k).j)=temp. y=x' end % READ DATA function[a. a(i. a c [p. x. c(i.c]=readdata. for i=1:1:n-1 for k=1:1:n if(abs(a(i.i).i.

for i=n:-1:1 temp=c(i). a(k.j)*x(j). for i=1:1:n-1 for k=i+1:1:n m=a(k. for j=i+1:1:n temp=temp-a(i. for k=i+1:1:n if(k==i+1) p(k.i).1)=0. end end end % BACK SUBSTITUTION function [x]=back(a. end end end p(1.c]=change(a.1)=a(i.i).1)=a(i.k)=a(k.k)-m*a(i. end end .c) n=length(c).i).i). end if(i+1==k) r(i. end x(i)=temp/a(i.i)/a(i. r(n.1)=a(k.1)=0.c) n=length(c).k). end % MAIN function [a.q(i.k). c(k)=c(k)-m*c(i).

OUTPUT Enter number of equations3 a[1][1]=1 a[1][2]=2 a[1][3]=0 c[1]=3 a[2][1]=2 a[2][2]=3 a[2][3]=1 c[2]=4 a[3][1]=0 a[3][2]=2 a[3][3]=-1 c[3]=1 a= 1 2 0 2 3 1 0 2 -1 c= 3 4 1 a= 1 2 0 2 3 1 0 2 -1 .

c= 3 4 1 p= 0 2 2 q= 1 3 -1 r= 2 1 0 y= 5 -1 -3 ans = 5 -1 -3>> .

j+1)+u(i. tn=input('\n Enter length of time interval='). end for (i=1:1:m-1) for (j=2:1:n-1) if (i==1) u(i+1.PROGRAM ON FINITE DIFFERENCE METHOD:-HYPERBOLIC EQUATION function hyperbolic clc. end .j)=(u(i.j)=u(i. n=xn/h+1. s=input('\n Enter initial condition='.j)=f((j-1)*h). for (i=2:1:m) u(i. u(i. xn=input('\n Enter length=').n)=br.j-1))/2.'s'). k=h/a. end end end u imagesc(u). h=input('\n Enter h=').j+1)+u(i. else u(i+1. bl=input('\n left boundary condition='). end for (j=1:1:n) u(1.1)=bl. br=input('\n right boundary condition='). a=input('\n INPUT VALUE OF a='). clear.j-1)-u(i-1. m=tn/k+1. f=inline(s).j).

OUTPUT INPUT VALUE OF a=2 left boundary condition=0 right boundary condition=0 Enter initial condition=X*(4-X) Enter length=4 Enter length of time interval=5 Enter h=1 u= >> 0 3 4 3 0 0 2 3 2 0 0 0 0 0 0 0 -2 -3 -2 0 0 -3 -4 -3 0 0 -2 -3 -2 0 0 0 0 0 0 0 2 3 2 0 0 3 4 3 0 0 2 3 2 0 0 0 0 0 0 .

5 5 5.1 2 3 4 5 6 7 8 9 10 11 0.5 2 2.5 .5 3 3.5 1 1.5 4 4.

fprintf('\nconstant b = %f'.x1]=readdata. a(2. a c [a.2)=sum_x3. fprintf('\n at x = %f.c]=pivote(a. end x1=input('\nEnter value of x for which y is to be determined : '). sum_x2y=sum_x2y+x(i)^2*y(i). y1=(x(1)*x1^2)+(x(2)*x1)+x(3).x1). sum_x4=sum_x4+x(i)^4. sum_x=0. sum_x4=0. for i=1:1:n sum_x=sum_x+x(i).x1]=readdata n=input('\nEnter no of data points : ').3)=n.2)=sum_xx. c(3)=sum_y. end function[a. sum_xy=sum_xy+x(i)*y(i).x(1)). c(1)=sum_x2y.y1).c. sum_x3=0. a(2.1)=sum_xx.c. a(1. c(2)=sum_xy. y(i)=input('\nEnter value of y : ').x1. a(2. sum_x3=sum_x3+x(i)^3. clear. [a. [a.1)=sum_x4.c). a(3. [x]=back(a. end a(1.2)=sum_x. sum_xx=0. sum_y=0.x(2)). a(1.1)=sum_x3. end function [a. fprintf('\nconstant c = %f'.c). for i=1:1:n x(i)=input('\nEnter value of x : ').c]=pivote(a. sum_xy=0. a(3. sum_xx=sum_xx+x(i)^2.c) .c]=upper(a.PROGRAM ON CURVE FITTING:-QUADRATIC POLYNOMIAL function quadraticcurvefitting clc.3)=sum_xx. y = %f'. sum_y=sum_y+y(i). a(3.x(3)). sum_x2y=0.c. fprintf('\nconstant a = %f'.3)=sum_x.

n=length(c).c]=upper(a. c(k)=temp. end c(k)=c(k)-temp*c(i). a(i.j)=temp.c.j). temp=temp-a(i. end end end end function[a. end . a(k. c(i)=c(k). for i=n:-1:1 temp=c(i).x1) n=length(c). end end end function[x]=back(a. for j=i+1:1:n.i)/a(i. end x=x'.j).i))) for j=1:1:n temp=a(i. for i=1:1:n-1 for k=i+1:1:n.c) n=length(c).j)*x(j).i))<abs(a(k.i). for j=1:1:n. end x(i)=temp/a(i.j)=a(k. temp=a(k.j)-temp*a(i.j)=a(k. end temp=c(i). for i=1:1:n-1 for k=i+1:1:n if(abs(a(i.i).j). a(k.

013406 constant b = 3.000000.731758>> .OUTPUT Enter value of y : 118 Enter value of x : 25 Enter value of y : 147 Enter value of x : 40 Enter value of y : 180 Enter value of x : 60 Enter value of y : 230 Enter value of x for which y is to be determined : 5 a= 15986161 300721 6181 300721 6181 151 6181 151 5 c= 1247483 27503 769 constant a = -0. y = 79.583565 constant c = 62.149088 at x = 5.

k=q*a*(h^2). bl=input('\n left boundary condition=').j)+q*u(i. f=inline(s).'s'). tn=input('\n Enter length of time interval='). q=input('\n Enter value of LAMBDA='). end for (i=1:1:m-1) for (j=2:1:n-1) u(i+1. for (i=2:1:m) u(i.j-1). m=tn/k+1.1)=bl.n-1)=br.j+1)-(2*q-1)*u(i. br=input('\n right boundary condition='). s=input('\n Enter initial condition='.j)=q*u(i. end end u imagesc(u) end . h=input('\n Enter h='). xn=input('\n Enter length='). end for (j=1:1:n) u(1. clear. a=input('\n INPUT VALUE OF a='). u(i. n=xn/h+1.PROGRAM ON FINITE DIFFERENCE METHOD:-PARABOLIC EQUATION function parabolic clc.j)=f((j-1)*h).

OUTPUT INPUT VALUE OF a=2 left boundary condition=0 right boundary condition=0 Enter initial condition=x*(4-x) Enter length=4 Enter length of time interval=5 Enter h=1 Enter value of LAMBDA=0.0000 0 0 2.7500 0.0000 2.7500 0 0 0.7500 1.5000 2.0000 4.0000 3.5000 0 0 1.5000 0.0000 0.0000 1.5000 1.0000 3.5000 0 .0000 0 0 0.5 u= >> 0 3.0000 0 0 1.0000 1.

1 2 3 4 5 6 0.5 2 2.5 1 1.5 4 4.5 .5 3 3.5 5 5.

PROGRAM ON FINITE DIFFERENCE METHOD:-POISSONS EQUATION function poisson clc.(i-1)*h))/4.j)=tt. contour(iy. s=input('\n ENTER F(X)='.j-1)-h^2*f((j-1)*h.j)+t(i. w=input('\n width='). end for k=1:1:100 for i=2:1:y-1 for j=2:1:x-1 t(i. t(i. t(y. x=l/h+1. for j=2:1:x-1 t(1. l=input('\n length=').j)+t(i-1.x)=tr. tt=input('\n TOP TEMPERATURE='). y=w/h+1. end for i=2:1:y-1 t(i. tl=input('\n LEFT TEMPERATURE=').j)=(t(i+1. iy=1:h:y.j+1)+t(i.'s').jx. tb=input('\n BOTTOM TEMPERATURE=').t). h=input('\n mesh size='). tr=input('\n RIGHT TEMPERATURE=').j)=tb. f=inline(s). end . clear. end end end jx=1:h:x.1)=tl.

0000 82.5000 75.5000 0 0 >> 0 0 0 0 .0000 0 0 75.OUTPUT BOTTOM TEMPERATURE=0 TOP TEMPERATURE=0 LEFT TEMPERATURE=0 RIGHT TEMPERATURE=0 ENTER F(X)=-10*(x^2+y^2+10) length=3 width=3 mesh size=1 t= 0 0 0 0 67.

4 3.5 1 1 1.5 2 1.5 3 2.5 2 2.5 3 3.5 4 .

i=i+1. while(i<n) f(i-1)=6*((y(i+1)-y(i))/(x(i+1)-x(i))-(y(i)-y(i-1))/(x(i)-x(i-1))). end i=2. end s1(n-2)=d(n-2)/b(n-2). while(i<n) h(i)=x(i+1)-x(i). c fprintf('\n constant matrix of TDMA'). end d=f'. end s(n)=0. b(i)=b(i)-m*c(i-1). end i=1. i=1. i=1. if(i<n-2) c(i)=h(i+1). end i=i+1. while(i<n-1) b(i)=2*(h(i)+h(i+1)).PROGRAM ON INTERPOLATION:-SPLINE INTERPOLATION function splineinter clc. a fprintf('\n b matrix of TDMA'). fprintf('\n Second derivatives are'). i=i+1. end s(1)=0. . for i=2:1:n-1 s(i)=s1(i-1). y(i)=input('\n ENTER y:'). d(i)=d(i)-m*d(i-1). clear. n=input('\n ENTER NUMBER OF DATA:'). b fprintf('\n c matrix of TDMA'). end fprintf('\n a matrix of TDMA'). for i=n-3:-1:1 s1(i)=(d(i)-c(i)*s1(i+1))/b(i). for i=1:1:n x(i)=input('\n ENTER x:'). end if(i>1) a(i)=h(i). f for i=2:1:n-2 m=a(i)/b(i-1).

5-x(3))^3)+bb(3)*((7. i=i+1. cc fprintf('\n Forth coefficient of all polynmial:').s while(i<=n-1) aa(i)=(s(i+1)-s(i))/(6*h(i)).5-x(1))^2)+cc(1)*(3.5-x(1))+dd(1) fprintf('\n value of y between second two data:'). bb fprintf('\n Third coefficient of all polynmial:'). dd(i)=y(i). bb(i)=s(i)/2.5-x(3))^2)+cc(3)*(7.5-x(3))+dd(3) end . yy=aa(3)*((7. end fprintf('\n First coefficient of all polynmial:'). aa fprintf('\n Second coefficient of all polynmial:'). dd fprintf('\n value of y between first two data:'). cc(i)=(y(i+1)-y(i))/h(i)-(2*h(i)*s(i)+h(i)*s(i+1))/6.5-x(1))^3)+bb(1)*((3. yy=aa(1)*((3. yy=aa(2)*((5-x(2))^3)+bb(2)*((5-x(2))^2)+cc(2)*(5-x(2))+dd(2) fprintf('\n value of y between third two data:').

2 ENTER x:7 ENTER y:2.OUTPUT ENTER NUMBER OF DATA:4 ENTER x:3 ENTER y:2.4716 0 .6499 -1.5000 b matrix of TDMA b= 8 9 c matrix of TDMA c= 2.8 ENTER x:4.5 a matrix of TDMA a= 0 2.5 ENTER x:9 ENTER y:0.5200 -9.5000 constant matrix of TDMA f= 9.5 ENTER y:1.1200 Second derivatives are s= 0 1.

5000 value of y between first two data: yy = 2.4791 -0.0189 Forth coefficient of all polynmial: dd = 2.2594 value of y between third two data: yy = 2.First coefficient of all polynmial: aa = 0.8249 -0.2417 -0.0833 value of y between second two data: yy = 1.2000 2.1226 Second coefficient of all polynmial: bb = 0 0.8000 1.1833 -0.7358 Third coefficient of all polynmial: cc = -1.3219 >> .2081 0.

end . fprintf('\n constant a=%f'. clear. sum_xy=sum_xy+(x(i)*y(i)).x(1)). of data points='). end x(1)=(((sum_x)*(sum_y))-((sum_xy)*n))/((-n*(sum_xx))+((sum_x)^2)). sum_x=0. y(i)=input('value of y=').x1. for i=1:1:n sum_x=sum_x+x(i). end x1=input('ENTER VALUE of x for which y is to be determined:'). sum_xx=0.y1). n=input('no. fprintf('\n y at x=%f is %f'. sum_y=sum_y+y(i). for i=1:1:n x(i)=input('\nvalue of x='). sum_y=0. x(2)=((sum_y)-(x(1)*(sum_x)))/n.x(2)).PROGRAM ON CURVE FITTING:-STRAIGHT LINE function straightline clc. sum_xy=0. fprintf('\n constant b=%f'. sum_xx=sum_xx+(x(i)^2). y1=x(1)*x1+x(2).

of data points=5 value of x=2.22036 value of x=11.60517 value of x=7 value of y=5.OUTPUT no.000000 is 4.34381 value of x=3.1 value of y=5.792304>> .6 value of y=5.4 value of y=4.65249 ENTER VALUE of x for which y is to be determined:5 constant a=0.47646 value of x=19.4 value of y=4.431014 y at x=5.072258 constant b=4.

8 5.2 0 2 4 6 8 10 12 14 16 18 20 .4 4.8 4.6 5.4 5.6 5.6 4.2 5 4.

end temp=c(i).j)=input(' '). end end % PIVOTING function [a.c).c).c]=pivote(a.i).c]=readdata.i. a(i. x end % READ DATA function [a. for i=1:1:n for j=1:1:n fprintf('a[%d][%d]= '.i.j).k).i))<abs(a(i. c(i)=c(k).j)=input(' '). a(i. a(i.c]=readdata n=input('\n Enter number of Equations=').c) n=length(c).j).j). clear.i))) for j=1:1:n temp=a(i. for i=1:1:n-1 for k=i+1:1:n if(abs(a(i.j).k)=a(i.PROGRAM ON SIMULTANEOUS EQUATIONS:-GAUSS SEIDAL METHOD function x=GaussSiedel clc. a c [x]=iterate(a. a c [a.j)=temp.k))) temp=a(i. c(i.c]=pivote(a. end end end for i=1:1:n for k=1:1:n if(abs(a(i. c(k)=temp.j)=a(k. fprintf('c[%d][%d]= '. a(k. [a.i)=temp.i))<abs(a(k. end j=1. end end end end % ITERATE function [x]=iterate(a. a(i.c) .

x(i)=temp/a(i. acc=input('\n ENTER ACCURACY:').n=length(c). end err=1. for j=1:1:n if(i~=j) temp=temp-a(i. for i=1:1:n x(i)=0.i).j)*x(j). end end end . end end err=x(i)-temp/a(i. while(abs(err)>acc) for i=1:1:n temp=c(i).i).

OUTPUT Enter number of Equations=3 a[1][1]= 130 a[1][2]= -30 a[1][3]= 0 c[1][1]= 500 a[2][1]= 90 a[2][2]= -90 a[2][3]= 0 c[2][1]= 0 a[3][1]= 40 a[3][2]= 60 a[3][3]= -120 c[3][1]= -200 a= 130 -30 0 90 -90 0 40 60 -120 c= 500 0 -200 a= 130 -30 0 90 -90 0 40 60 -120 .

0000 5.c= 500 0 -200 ENTER ACCURACY:0.8333 >> .0000 5.000001 x= 5.

a c [x]=iterate(a. a(i.j)=a(k.j)=input(' ').i. [a.c) n=length(c).j)=temp. x end % READ DATA function [a.j). acc=input('\n ENTER ACCURACY:'). end end % PIVOTING function [a.c).j)=input(' '). while(abs(err)>acc) .c) n=length(c). a c [a. end end end end % ITERATE function [x]=iterate(a. end err=1.j). a(k. end j=1.i.c]=pivote(a. c(i.c]=readdata n=input('\n Enter number of Equations='). c(k)=temp. for i=1:1:n for j=1:1:n fprintf('a[%d][%d]= '. for i=1:1:n-1 for k=1:1:n if(abs(a(i.c). fprintf('c[%d][%d]= '. a(i.c]=pivote(a.i))<abs(a(k.c]=readdata. c(i)=c(k).j). end temp=c(i).PROGRAM ON SIMULTANEOUS EQUATION:-GAUSS SEIDAL WITH RELAXATION FACTOR function x=GaussSiedelREL clc. b=input('\n ENTER RELAXATATION FACTOR=').i))) for j=1:1:n temp=a(i. clear.j). for i=1:1:n x(i)=0.

x(i)=b*temp/a(i.j)*x(j). end end end .for i=1:1:n temp=c(i). end end err=b*(x(i)-temp/a(i.i)+(1-b)*x(i).i)). for j=1:1:n if(i~=j) temp=temp-a(i.

OUTPUT Enter number of Equations=3 a[1][1]= 130 a[1][2]= -30 a[1][3]= 0 c[1][1]= 500 a[2][1]= 90 a[2][2]= -90 a[2][3]= 0 c[2][1]= 0 a[3][1]= 40 a[3][2]= 60 a[3][3]= -120 c[3][1]= -200 a= 130 -30 0 90 -90 0 40 60 -120 c= 500 0 -200 a= 130 -30 0 90 -90 0 40 60 -120 .

8333 >> .9 x= 5.c= 500 0 -200 ENTER ACCURACY:0.0000 5.000001 ENTER RELAXATATION FACTOR=0.0000 5.

50).j+1)+t(i. tb = input('\nEnter bottom temperature:'). tl = input('\nEnter left temperature:'). l = input('\nEnter length:'). h = input('\nEnter mesh size:'). else t(i. for k=1:1:n for i=2:1:ny-1 for j=2:1:nx if(j<nx) t(i.1) = tl. nx = l/h+1. clear. for i=2:1:ny-1 t(i.j) = (t(i+1.j-1))/4. end n = input('\nEnter number of iterations:').j) = (t(i+1.y.j)+t(i.j) = tb.j-1))/4. w = input('\nEnter width:'). end .j)+t(i. t(ny. y=1:h:ny.j-1)+t(i. end for j=2:1:nx t(1. end end end end t x=1:h:nx.j)+ t(i-1.t. contour (x. tt = input('\nEnter top temperature:'). ny = w/h+1.j) = tt.j)+t(i-1.PROGRAM ON FINITE DIFFERENCE METHOD:-LAPLACE [ONE INSULATED BOUNDARY] function x = laplace1insulatedboundary clc.

0000 >> .2222 30.7778 88.0000 100.0000 100.0000 100.0000 72.OUTPUT Enter bottom temperature:100 Enter left temperature:30 Enter top temperature:100 Enter length:3 Enter width:3 Enter mesh size:1 Enter number of iterations:100 t= 0 100.0000 30.0000 100.3333 92.3333 92.0000 72.2222 0 100.7778 88.

4 3.5 2 1.5 4 .5 1 1 1.5 3 2.5 3 3.5 2 2.

j-1))/4.t.PROGRAM ON FINITE DIFFERENCE METHOD:-LAPLACE [TWO INSULATED BOUNDARY] function x = laplace2insulatedboundaries clc. ny = w/h+1. y=1:h:ny.50).j)+t(i.j-1))/4. clear. end . l = input('\nEnter length:'). nx = l/h+1.j)+t(i+1.j) = (t(i+1.j)+ t(i-1.j+1)+t(i.j)+t(i. end end end end t x=1:h:nx. w = input('\nEnter width:').j) = (t(i-1. else t(i.j+1)+t(i. for i=1:1:ny t(i. contour (x. t(i.nx) = tr. elseif(i==1) t(i.j) = (t(i+1. for k=1:1:n for i=1:1:ny for j=2:1:nx-1 if(i>1)&&(i<ny) t(i.y. tl = input('\nEnter left temperature:'). tr = input('\nEnter right temperature:').j-1))/4. h = input('\nEnter mesh size:').j)+ t(i-1.j)+t(i. end n = input('\nEnter number of iterations:').1) = tl.j+1)+t(i.

5 3 2.0000 66.5 4 .0000 66.5 2 2.5 1 1 1.6667 33.OUTPUT Enter left temperature:100 Enter right temperature:0 Enter length:3 Enter width:3 Enter mesh size:1 Enter number of iterations:100 t= 100.0000 66.6667 33.3333 0 100.0000 66.6667 33.3333 0 100.3333 0 >> 4 3.3333 0 100.5 2 1.6667 33.5 3 3.