SlideShare a Scribd company logo
1 of 18
Download to read offline
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
1
Numerical Methods by MATLAB
Mechanical Engineering
Prepared by
Dr.D.P.Bhaskar
Department of Mechanical Engineering
Sanjivani College of Engineering, Kopargaon
Maharastra
(An Autonomous Institute SP Pune University)
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
2
Unit 1 Roots of Equation
%Bisection Method
clc
clear all
f=inline('x‐cos(x)'); acc=0.001;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=1:100
x1=input('Enter new x1');
x2=input('Enter new x2');
if(f(x1)*f(x2)<0) break
end
end
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐n');
fprintf('I x1 x2 x3 Acc Error)');
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐');
for i=1:100
x3=(x1+x2)/2;
b=abs(x1‐x2); c=(f(x1)*f(x3));
fprintf('n%d %.4f %.4f %.4f %.4f %.4f ',i,x1,x2,x3,b,c);
if(b<acc) break
else if(c>0) x1=x3; else x2=x3; end
end
end
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐');
fprintf('n Root=%f',x3);
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
3
%Newton Raphson Method
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
f=inline('x.^3‐cos(x)*cos(x)');
fd=inline('2*cos(x)*sin(x) + 3*x.^2');
acc=0.001; x1=1;
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐n');
fprintf('I x1 f(x1) fd(x1) x2 Acc');
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐');
abs(f(x1))
abs(fd(x1))
for i=1:100
x2=x1‐f(x1)/fd(x1);
b=abs(x1‐x2);
fprintf('n%d %.4f %.4f %.4f %.4f %.4f',i,x1, f(x1), fd(x1),x2,b);
if(b <acc) break
else x1=x2;
end
end
fprintf('‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐');
fprintf('n Root=%f',x2);
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
4
Unit 2 Simultaneous Equation
%2.0 GEM
clc
clear all
n=3; m=n+1;
a=[1 2 2 7;2 ‐4 1 ‐5;1 1 2 5];
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for k=1:(n‐1) %Ip=Jp=1 2 3
for i=k+1:n
PVT= a(k,k); TL= a(i,k); p=TL/PVT;
for j=k:m
a(i,j)=a(i,j)‐p*a(k,j);
end
end
end
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=n:‐1:1
sum=0.0;
for j=i+1:n
sum=sum+a(i,j)*x(j);
end
x(i)=(a(i,n+1)‐sum)/a(i,i);
end
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=1:n
fprintf('x(%d)=%0.2fn',i,x(i));
end
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
5
% GEM with Partial Pivoting
clc
clear all
n=3; m=n+1;
a=[1 2 2 7;2 ‐4 1 ‐5;1 1 2 5];
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for k = 1:n‐1
for i = k+1:n
if (abs(a(k,k)) < abs(a(i,k)))
a([k i],:) = a([i k],:);
end
end
end
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for k=1:(n‐1) %Ip=Jp=1 2 3
for i=k+1:n
PVT= a(k,k); TL= a(i,k); p=TL/PVT;
for j=k:m
a(i,j)=a(i,j)‐p*a(k,j);
end
end
end
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=n:‐1:1
sum=0.0;
for j=i+1:n
sum=sum+a(i,j)*x(j);
end
x(i)=(a(i,n+1)‐sum)/a(i,i);
end
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=1:n
fprintf('x(%d)=%0.2fn',i,x(i));
end
%SOLVER
clc
clear all
a=[1 2 2 ;2 ‐4 1 ;1 1 2];
b=[4;5;6];
x=inv(x)*b
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
6
%GAUSS SEIDAL METHOD
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
f1=inline('(13‐4*y‐3*z)/2');
f2=inline('(16‐3*x‐z)/‐6');
f3=inline('(9‐x‐3*y)/2');
x1=0; y1=0; z1=0; acc=0.001;
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐');
fprintf('n I X Y Z ');
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐');
for i=1:100
x2=f1(y1,z1); y2=f2(x2,z1); z2=f3(x2,y2);
fprintf('n %d %f %f %fn',i,x2,y2,z2);
a=abs(x1‐x2); b=abs(y1‐y2); c=abs(z1‐z2);
if (a<acc && b<acc && c<acc) break
else x1=x2; z1=z2; y1=y2;
end
end
fprintf('‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐');
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
7
Unit 3 Curve Fitting
%3.0 Curve fitting F Line Yf=C0+C1(X)
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐Direct input of Data‐‐‐‐‐‐‐‐‐‐‐
x=[1 2 3 4];
y=[2 6 12 20];
n=length(x);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐OR‐User UInput of data‐‐‐‐‐
% n=input('Enter n=');
% for i=1:n
% fprintf('Enter x(%d)=',i);
% x(i)=input('');
% fprintf('Enter y(%d)=',i);
% y(i)=input('');
% end
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
s1=sum(x); s2=sum(x.^2); s3=sum(y);
s4=sum(x.*y);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
d=[n s1;
s1 s2];
d1=[s3 s1;
s4 s2];
d2=[n s3;
s1 s4];
d=det(d); d1=det(d1); d2=det(d2);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
c0=d1/d; c1=d2/d;
fprintf('BEST FIT ,Yn=%0.3f+%0.3f(X)n',c0,c1)
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
yn=c0+c1*x;
plot(x,y,'*',x,yn)
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
8
% Quadratic FITTING Yf=C0+C1(X)+C2(x^2);
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
x=[1 2 3 4 5 6 7 8 9];
y=[2 6 7 8 10 11 11 10 9];
n=9;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
x2=x.^2; x3=x.^3; x4=x.^4; xy=x.*y; x2y=(x.^2).*y;
s1=sum(x); s2=sum(x2); s3=sum(x3); s4=sum(x4); s5=sum(y); s6=sum(xy); s7=sum(x2y);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
d=[n s1 s2;
s1 s2 s3
s2 s3 s4];
d1=[s5 s1 s2;
s6 s2 s3
s7 s3 s4];
d2=[n s5 s2;
s1 s6 s3
s2 s7 s4];
d3=[n s1 s5;
s1 s2 s6
s2 s3 s7];
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
d=det(d); d1=det(d1); d2=det(d2); d3=det(d3); c0=d1/d; c1=d2/d; c2=d3/d;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
fprintf('BEST FIT ,Yn=%0.3f+%0.3f(X)+%0.3f(x^2) /n',c0,c1,c2)
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
yn=c0+c1*x+c2*x2;
plot(x,y,'*',x,yn,'r')
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
9
%Power Equation
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐Power Equation‐‐‐‐‐‐‐‐‐‐‐
%PV^Gamma=C
p=[0.5 1.0 1.5 2.0 2.5 3.0];
v=[1.62 1.0 0.75 0.62 0.52 0.46];
n=6;
y=log10(p);
x=log10(v);
xy=x.*y;
x2=x.^2;
s1=sum(x); s2=sum(x2); s3=sum(y); s4=sum(xy);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
d=n*s2‐s1*s1;
d1=s3*s2‐s4*s1;
d2=n*s4‐s1*s3;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
c0=d1/d; c1=d2/d;
gamma=‐c1;
c=exp(c0);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
fprintf('PV^%0.3f=%f/n',gamma,c)
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
%plot(p,v);
for i=1:n
fprintf('%f %f %f %f %f %fn',v(i),p(i),x(i),y(i),x2(i),xy(i));
end
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
10
%Exponential
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐Exponential‐‐‐‐‐‐‐‐‐‐‐
%y=ae^bx
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
x=[2 4 6 8];
y=[25 38 56 84];
n=length(x);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
y1=log(y);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
x2=x.^2; xy1=x.*y1;
s1=sum(x); s2=sum(x2); s3=sum(y1); s4=sum(xy1);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
d=n*s2‐s1*s1;
d1=s3*s2‐s4*s1;
d2=n*s4‐s1*s3;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
c0=d1/d; c1=d2/d;
a=exp(c0);
b=c1;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
fprintf('y=%0.3f e^(%0.3fx) n',a,b)
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=1:n
fprintf('%f %f %f %f %f n',x(i),y(i),y1(i),x2(i),xy1(i));
end
%Solver
clear all
x=[19 25 30 36 40 45 50];
y=[76 77 79 80 82 83 85];
d=1; %d=1 (line) d=2(parabola)
c=polyfit(x,y,d)
% yn = polyval(c, x);
yn=c(2)+c(1)*x;
plot(x,y,'*',x,yn)
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
11
Unit 4 ODE & PDE
%EULERS METHOD
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
f=inline('x*x*y+y*y');
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
x1=input('ENTER x1='); y1=input('ENTER y1=');
xn=input('ENTER xn='); n=input('ENTER n=');
h=(xn‐x1)/n;
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ');
fprintf('n X Y ');
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ');
fprintf('n %0.3f %0.3f',x1,y1);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=1:n
x2=x1+h;
y2=y1+h*f(x1,y1);
fprintf('n %0.3f %0.3f',x2,y2);
x1=x2; y1=y2;
end
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ');
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
12
%RK4
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
f=inline('x*x*y+y*y');%(Sample function)
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
x1=input('ENTER x1='); y1=input('ENTER y1='); % BCns
xn=input('ENTER xn='); n=input('ENTER n=');
h=(xn‐x1)/n;
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ');
fprintf('n X Y ');
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ');
fprintf('n %0.3f %0.3f',x1,y1);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=1:n
s1=h*f(x1,y1); s2=h*f(x1+h/2,y1+s1/2);
s3=h*f(x1+h/2,y1+s2/2); s4=h*f(x1+h,y1+s3);
s=(s1+2*s2+2*s3+s4)/6;
y2=y1+s; x2=x1+h;
fprintf('n %0.3f %0.3f',x2,y2);
x1=x2; y1=y2;
end
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ');
%SOLVER
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
f=inline('x+y');
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
x1=0; xn=0.2; y1=2; h=0.1;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
[x,y]=ode23(f,[x1:h:xn],y1)
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
13
%Simultaneous ODE %RK2
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
f1=inline('x+(y*z)');%(Sample function)
f2=inline('(x*x)‐(y*y)');%(Sample function)
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
x1=0; y1=1; z1=0; xn=0.2;% BCns Direct Input
n=2; % Number of strips Direct Input
h=(xn‐x1)/n;
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ');
fprintf('n X Y ');
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ');
fprintf('n %0.3f %0.3f',x1,y1);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=1:n
s1=h*f1(x1,y1,z1); k1=h*f2(x1,y1,z1);
s2=h*f1(x1+h,y1+s1,z1+k1); k2=h*f2(x1+h,y1+s1,z1+k1);
s=(s1+s2)/2; k=(k1+k2)/2;
y2=y1+s; z2=z1+k; x2=x1+h;
fprintf('n %0.3f %0.3f %0.3f',x2,y2,z2);
x1=x2; y1=y2; z1=z2;
end
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
14
%Elliptical Laplace Equation
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
clc
clear all
rh=0;lh=100;top=100;bot=0;itr=4;
n=3;m=3;h=1;k=1;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=1:n+1
for j=1:m+1
a(i,j)=0;
end
end
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=2:(n)
a(i,1)=bot; a(i,m+1)=top;
end
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for j=2:(m)
a(1,j)=lh; a(m+1,j)=rh;
end
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for k=1:itr
for i=2:n
for j=2:m
a(i,j)=(a(i‐1,j)+ a(i+1,j)+a(i,j‐1)+ a(i,j+1))/4;
end
end
end
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
disp(a)
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
15
Unit 5 Interpolation
%LAGRANGES Method
clc
clear all
xp=1.1;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
x=[1 1.2 1.3 1.5];
y=[1 1.0954 1.1402 1.2247];
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐OR‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
n=length(x);
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
sum=0;
for i=1:n
term=y(i);
for j=1:n
if(i~=j)
term=term*(xp‐x(j))/(x(i)‐x(j))
end
end
sum=sum+term
end
fprintf('x=%.3f,yp=%.5f',xp,sum)
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
% n=input('Enter n=');
% for i=1:n
% fprintf('Enter x(%d)=',i);
% x(i)=input('');
% fprintf('Enter y(%d)=',i);
% y(i)=input('');
% end
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
16
%Newton Forward Method
clc
clear all
x=[0 1 2 3 4 5]; y=[1 2 9 28 65 126];
% x=input('Enter [x]='); y=input('Enter [y]=');
n=length(x); h=x(2)‐x(1);
xp=input('xp=');
%‐‐‐‐‐‐‐‐‐‐‐‐‐Table Calculations‐‐‐
for j=1:(n‐1)
for i=1:(n‐j)
if(j==1) f(i,j)=y(i+1)‐y(i);
else f(i,j)=f(i+1,j‐1)‐f(i,j‐1);
end
end
end
fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐NF TABLE ‐‐‐‐‐‐‐‐')
for i=1:n
fprintf('n %0.2f t %0.2f',x(i),y(i));
for j=1:(n‐i)
fprintf('tt %0.2f',f(i,j));
end
end
fprintf('‐‐‐‐‐‐‐‐‐‐‐‐‐‐TABLE ENDS‐‐‐‐‐‐‐')
sum=y(1);
for i=1:(n‐1)
prod=f(1,i);
for j=1:i
prod=prod*(xp‐x(j))/(j*h);
end
sum=sum+prod;
end
fprintf(' YP=%f',sum);
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
17
Unit 6 Integration
%TRAP
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
f=inline('x.^3');
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
a=input('Enter Lower Limit,a='); b=input('Enter Upper Limit,b=');
ns=1; % depends on method
na=input('Enter Number of application ,na=');
n=na*ns;
h=(b‐a)/n;
sum=0;
x1=a;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=1:na
sum=sum+f(x1)*1+f(x1+h)*1; % depends on method
x1=(x1+h);
end
Area=sum*h/2; % depends on method
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
fprintf('n Area of integration=%0.2f',Area)
% Solver
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
f =inline('x.^3');
a=2;b=3;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Q = quad(f,a,b)
NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON]
18
% Double Trap Integration
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
clc
clear all
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
f=inline('x+y');
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
ns=1;
a=1;b=3;c=0;d=2;na=2;ma=2;
n=na*ns;m=ns*ma;
h=(b‐a)/n; k=(d‐c)/m;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
y1=c;
for j=1:m+1
x1=a;
sum=0;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
for i=1:na
sum=sum+f(x1,y1)+f((x1+h),y1);
x1=(x1+h);
end
s(j)= h/2*sum;
y1=y1+k;
end
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
sum=0;
for j=2:ma
sum=sum+s(j);
end
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
sum=sum*2;
sum=sum+s(1)+s(m+1);
sum=sum*k/2
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
fprintf('Volume=%f',sum);
%Solver Double Integration (dblquad)
clc
clear all
f =inline('x+y')
a=1;b=3;c=0;d=2;
%‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Volume=dblquad(f,a,b,c,d);
fprintf(' Volume of integration=%0.2f',Volume);

More Related Content

Similar to Numericam Methods using Matlab.pdf

ACCURATE Q-PREDICTION FOR RFIC SPIRAL INDUCTORS USING THE 3DB BANDWIDTH
ACCURATE Q-PREDICTION FOR RFIC SPIRAL INDUCTORS  USING THE 3DB BANDWIDTHACCURATE Q-PREDICTION FOR RFIC SPIRAL INDUCTORS  USING THE 3DB BANDWIDTH
ACCURATE Q-PREDICTION FOR RFIC SPIRAL INDUCTORS USING THE 3DB BANDWIDTHIlango Jeyasubramanian
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfmeerobertsonheyde608
 
Simple C programs
Simple C programsSimple C programs
Simple C programsab11cs001
 
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU HyderabadSrinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU HyderabadSrinivas Reddy Amedapu
 
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH HyderabadSrinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH HyderabadSrinivas Reddy Amedapu
 
Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in cBUBT
 
C graphics programs file
C graphics programs fileC graphics programs file
C graphics programs fileshubham kanojia
 
Computer applications in civil engineering lab
Computer applications in civil engineering labComputer applications in civil engineering lab
Computer applications in civil engineering labVivek Kumar Sinha
 
FAIQ MANUAL.pdf
FAIQ MANUAL.pdfFAIQ MANUAL.pdf
FAIQ MANUAL.pdfFaiqAli57
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignmentashikul akash
 
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdfIncorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdfaartechindia
 

Similar to Numericam Methods using Matlab.pdf (20)

ACCURATE Q-PREDICTION FOR RFIC SPIRAL INDUCTORS USING THE 3DB BANDWIDTH
ACCURATE Q-PREDICTION FOR RFIC SPIRAL INDUCTORS  USING THE 3DB BANDWIDTHACCURATE Q-PREDICTION FOR RFIC SPIRAL INDUCTORS  USING THE 3DB BANDWIDTH
ACCURATE Q-PREDICTION FOR RFIC SPIRAL INDUCTORS USING THE 3DB BANDWIDTH
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
 
Simple C programs
Simple C programsSimple C programs
Simple C programs
 
C lab excellent
C lab excellentC lab excellent
C lab excellent
 
C and Data Structures Lab Solutions
C and Data Structures Lab SolutionsC and Data Structures Lab Solutions
C and Data Structures Lab Solutions
 
C and Data Structures
C and Data Structures C and Data Structures
C and Data Structures
 
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU HyderabadSrinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
 
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH HyderabadSrinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
 
Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
 
C graphics programs file
C graphics programs fileC graphics programs file
C graphics programs file
 
Lab manualsahu[et&amp;t]
Lab manualsahu[et&amp;t]Lab manualsahu[et&amp;t]
Lab manualsahu[et&amp;t]
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
 
Computer applications in civil engineering lab
Computer applications in civil engineering labComputer applications in civil engineering lab
Computer applications in civil engineering lab
 
FAIQ MANUAL.pdf
FAIQ MANUAL.pdfFAIQ MANUAL.pdf
FAIQ MANUAL.pdf
 
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
 
Dsp iit workshop
Dsp iit workshopDsp iit workshop
Dsp iit workshop
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
 
C language program
C language programC language program
C language program
 
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdfIncorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
 

More from Dhiraj Bhaskar (11)

4.pdf
4.pdf4.pdf
4.pdf
 
1.pdf
1.pdf1.pdf
1.pdf
 
I C Engine components design
I C Engine components designI C Engine components design
I C Engine components design
 
Optimum design
Optimum designOptimum design
Optimum design
 
Pressure vessel
Pressure vesselPressure vessel
Pressure vessel
 
Thin and Thick Cylinders
Thin and Thick CylindersThin and Thick Cylinders
Thin and Thick Cylinders
 
3
33
3
 
2
22
2
 
1
11
1
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
MACHINE TOOL GEAR BOX
MACHINE TOOL GEAR BOXMACHINE TOOL GEAR BOX
MACHINE TOOL GEAR BOX
 

Recently uploaded

MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 

Recently uploaded (20)

MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 

Numericam Methods using Matlab.pdf

  • 1. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 1 Numerical Methods by MATLAB Mechanical Engineering Prepared by Dr.D.P.Bhaskar Department of Mechanical Engineering Sanjivani College of Engineering, Kopargaon Maharastra (An Autonomous Institute SP Pune University)
  • 2. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 2 Unit 1 Roots of Equation %Bisection Method clc clear all f=inline('x‐cos(x)'); acc=0.001; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=1:100 x1=input('Enter new x1'); x2=input('Enter new x2'); if(f(x1)*f(x2)<0) break end end fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐n'); fprintf('I x1 x2 x3 Acc Error)'); fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐'); for i=1:100 x3=(x1+x2)/2; b=abs(x1‐x2); c=(f(x1)*f(x3)); fprintf('n%d %.4f %.4f %.4f %.4f %.4f ',i,x1,x2,x3,b,c); if(b<acc) break else if(c>0) x1=x3; else x2=x3; end end end fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐'); fprintf('n Root=%f',x3);
  • 3. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 3 %Newton Raphson Method clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ f=inline('x.^3‐cos(x)*cos(x)'); fd=inline('2*cos(x)*sin(x) + 3*x.^2'); acc=0.001; x1=1; fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐n'); fprintf('I x1 f(x1) fd(x1) x2 Acc'); fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐'); abs(f(x1)) abs(fd(x1)) for i=1:100 x2=x1‐f(x1)/fd(x1); b=abs(x1‐x2); fprintf('n%d %.4f %.4f %.4f %.4f %.4f',i,x1, f(x1), fd(x1),x2,b); if(b <acc) break else x1=x2; end end fprintf('‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐'); fprintf('n Root=%f',x2);
  • 4. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 4 Unit 2 Simultaneous Equation %2.0 GEM clc clear all n=3; m=n+1; a=[1 2 2 7;2 ‐4 1 ‐5;1 1 2 5]; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for k=1:(n‐1) %Ip=Jp=1 2 3 for i=k+1:n PVT= a(k,k); TL= a(i,k); p=TL/PVT; for j=k:m a(i,j)=a(i,j)‐p*a(k,j); end end end %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=n:‐1:1 sum=0.0; for j=i+1:n sum=sum+a(i,j)*x(j); end x(i)=(a(i,n+1)‐sum)/a(i,i); end %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=1:n fprintf('x(%d)=%0.2fn',i,x(i)); end
  • 5. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 5 % GEM with Partial Pivoting clc clear all n=3; m=n+1; a=[1 2 2 7;2 ‐4 1 ‐5;1 1 2 5]; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for k = 1:n‐1 for i = k+1:n if (abs(a(k,k)) < abs(a(i,k))) a([k i],:) = a([i k],:); end end end %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for k=1:(n‐1) %Ip=Jp=1 2 3 for i=k+1:n PVT= a(k,k); TL= a(i,k); p=TL/PVT; for j=k:m a(i,j)=a(i,j)‐p*a(k,j); end end end %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=n:‐1:1 sum=0.0; for j=i+1:n sum=sum+a(i,j)*x(j); end x(i)=(a(i,n+1)‐sum)/a(i,i); end %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=1:n fprintf('x(%d)=%0.2fn',i,x(i)); end %SOLVER clc clear all a=[1 2 2 ;2 ‐4 1 ;1 1 2]; b=[4;5;6]; x=inv(x)*b
  • 6. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 6 %GAUSS SEIDAL METHOD clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ f1=inline('(13‐4*y‐3*z)/2'); f2=inline('(16‐3*x‐z)/‐6'); f3=inline('(9‐x‐3*y)/2'); x1=0; y1=0; z1=0; acc=0.001; fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐'); fprintf('n I X Y Z '); fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐'); for i=1:100 x2=f1(y1,z1); y2=f2(x2,z1); z2=f3(x2,y2); fprintf('n %d %f %f %fn',i,x2,y2,z2); a=abs(x1‐x2); b=abs(y1‐y2); c=abs(z1‐z2); if (a<acc && b<acc && c<acc) break else x1=x2; z1=z2; y1=y2; end end fprintf('‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐');
  • 7. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 7 Unit 3 Curve Fitting %3.0 Curve fitting F Line Yf=C0+C1(X) clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐Direct input of Data‐‐‐‐‐‐‐‐‐‐‐ x=[1 2 3 4]; y=[2 6 12 20]; n=length(x); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐OR‐User UInput of data‐‐‐‐‐ % n=input('Enter n='); % for i=1:n % fprintf('Enter x(%d)=',i); % x(i)=input(''); % fprintf('Enter y(%d)=',i); % y(i)=input(''); % end %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ s1=sum(x); s2=sum(x.^2); s3=sum(y); s4=sum(x.*y); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ d=[n s1; s1 s2]; d1=[s3 s1; s4 s2]; d2=[n s3; s1 s4]; d=det(d); d1=det(d1); d2=det(d2); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ c0=d1/d; c1=d2/d; fprintf('BEST FIT ,Yn=%0.3f+%0.3f(X)n',c0,c1) %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ yn=c0+c1*x; plot(x,y,'*',x,yn) %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
  • 8. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 8 % Quadratic FITTING Yf=C0+C1(X)+C2(x^2); clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x=[1 2 3 4 5 6 7 8 9]; y=[2 6 7 8 10 11 11 10 9]; n=9; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x2=x.^2; x3=x.^3; x4=x.^4; xy=x.*y; x2y=(x.^2).*y; s1=sum(x); s2=sum(x2); s3=sum(x3); s4=sum(x4); s5=sum(y); s6=sum(xy); s7=sum(x2y); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ d=[n s1 s2; s1 s2 s3 s2 s3 s4]; d1=[s5 s1 s2; s6 s2 s3 s7 s3 s4]; d2=[n s5 s2; s1 s6 s3 s2 s7 s4]; d3=[n s1 s5; s1 s2 s6 s2 s3 s7]; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ d=det(d); d1=det(d1); d2=det(d2); d3=det(d3); c0=d1/d; c1=d2/d; c2=d3/d; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ fprintf('BEST FIT ,Yn=%0.3f+%0.3f(X)+%0.3f(x^2) /n',c0,c1,c2) %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ yn=c0+c1*x+c2*x2; plot(x,y,'*',x,yn,'r') %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
  • 9. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 9 %Power Equation clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐Power Equation‐‐‐‐‐‐‐‐‐‐‐ %PV^Gamma=C p=[0.5 1.0 1.5 2.0 2.5 3.0]; v=[1.62 1.0 0.75 0.62 0.52 0.46]; n=6; y=log10(p); x=log10(v); xy=x.*y; x2=x.^2; s1=sum(x); s2=sum(x2); s3=sum(y); s4=sum(xy); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ d=n*s2‐s1*s1; d1=s3*s2‐s4*s1; d2=n*s4‐s1*s3; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ c0=d1/d; c1=d2/d; gamma=‐c1; c=exp(c0); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ fprintf('PV^%0.3f=%f/n',gamma,c) %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ %plot(p,v); for i=1:n fprintf('%f %f %f %f %f %fn',v(i),p(i),x(i),y(i),x2(i),xy(i)); end
  • 10. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 10 %Exponential clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐Exponential‐‐‐‐‐‐‐‐‐‐‐ %y=ae^bx %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x=[2 4 6 8]; y=[25 38 56 84]; n=length(x); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ y1=log(y); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x2=x.^2; xy1=x.*y1; s1=sum(x); s2=sum(x2); s3=sum(y1); s4=sum(xy1); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ d=n*s2‐s1*s1; d1=s3*s2‐s4*s1; d2=n*s4‐s1*s3; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ c0=d1/d; c1=d2/d; a=exp(c0); b=c1; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ fprintf('y=%0.3f e^(%0.3fx) n',a,b) %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=1:n fprintf('%f %f %f %f %f n',x(i),y(i),y1(i),x2(i),xy1(i)); end %Solver clear all x=[19 25 30 36 40 45 50]; y=[76 77 79 80 82 83 85]; d=1; %d=1 (line) d=2(parabola) c=polyfit(x,y,d) % yn = polyval(c, x); yn=c(2)+c(1)*x; plot(x,y,'*',x,yn)
  • 11. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 11 Unit 4 ODE & PDE %EULERS METHOD clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ f=inline('x*x*y+y*y'); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x1=input('ENTER x1='); y1=input('ENTER y1='); xn=input('ENTER xn='); n=input('ENTER n='); h=(xn‐x1)/n; fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ '); fprintf('n X Y '); fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ '); fprintf('n %0.3f %0.3f',x1,y1); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=1:n x2=x1+h; y2=y1+h*f(x1,y1); fprintf('n %0.3f %0.3f',x2,y2); x1=x2; y1=y2; end fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ');
  • 12. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 12 %RK4 clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ f=inline('x*x*y+y*y');%(Sample function) %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x1=input('ENTER x1='); y1=input('ENTER y1='); % BCns xn=input('ENTER xn='); n=input('ENTER n='); h=(xn‐x1)/n; fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ '); fprintf('n X Y '); fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ '); fprintf('n %0.3f %0.3f',x1,y1); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=1:n s1=h*f(x1,y1); s2=h*f(x1+h/2,y1+s1/2); s3=h*f(x1+h/2,y1+s2/2); s4=h*f(x1+h,y1+s3); s=(s1+2*s2+2*s3+s4)/6; y2=y1+s; x2=x1+h; fprintf('n %0.3f %0.3f',x2,y2); x1=x2; y1=y2; end fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ '); %SOLVER clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ f=inline('x+y'); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x1=0; xn=0.2; y1=2; h=0.1; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ [x,y]=ode23(f,[x1:h:xn],y1) %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
  • 13. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 13 %Simultaneous ODE %RK2 clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ f1=inline('x+(y*z)');%(Sample function) f2=inline('(x*x)‐(y*y)');%(Sample function) %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x1=0; y1=1; z1=0; xn=0.2;% BCns Direct Input n=2; % Number of strips Direct Input h=(xn‐x1)/n; fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ '); fprintf('n X Y '); fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ '); fprintf('n %0.3f %0.3f',x1,y1); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=1:n s1=h*f1(x1,y1,z1); k1=h*f2(x1,y1,z1); s2=h*f1(x1+h,y1+s1,z1+k1); k2=h*f2(x1+h,y1+s1,z1+k1); s=(s1+s2)/2; k=(k1+k2)/2; y2=y1+s; z2=z1+k; x2=x1+h; fprintf('n %0.3f %0.3f %0.3f',x2,y2,z2); x1=x2; y1=y2; z1=z2; end
  • 14. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 14 %Elliptical Laplace Equation %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ clc clear all rh=0;lh=100;top=100;bot=0;itr=4; n=3;m=3;h=1;k=1; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=1:n+1 for j=1:m+1 a(i,j)=0; end end %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=2:(n) a(i,1)=bot; a(i,m+1)=top; end %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for j=2:(m) a(1,j)=lh; a(m+1,j)=rh; end %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for k=1:itr for i=2:n for j=2:m a(i,j)=(a(i‐1,j)+ a(i+1,j)+a(i,j‐1)+ a(i,j+1))/4; end end end %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ disp(a)
  • 15. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 15 Unit 5 Interpolation %LAGRANGES Method clc clear all xp=1.1; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x=[1 1.2 1.3 1.5]; y=[1 1.0954 1.1402 1.2247]; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐OR‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ n=length(x); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ sum=0; for i=1:n term=y(i); for j=1:n if(i~=j) term=term*(xp‐x(j))/(x(i)‐x(j)) end end sum=sum+term end fprintf('x=%.3f,yp=%.5f',xp,sum) %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ % n=input('Enter n='); % for i=1:n % fprintf('Enter x(%d)=',i); % x(i)=input(''); % fprintf('Enter y(%d)=',i); % y(i)=input(''); % end
  • 16. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 16 %Newton Forward Method clc clear all x=[0 1 2 3 4 5]; y=[1 2 9 28 65 126]; % x=input('Enter [x]='); y=input('Enter [y]='); n=length(x); h=x(2)‐x(1); xp=input('xp='); %‐‐‐‐‐‐‐‐‐‐‐‐‐Table Calculations‐‐‐ for j=1:(n‐1) for i=1:(n‐j) if(j==1) f(i,j)=y(i+1)‐y(i); else f(i,j)=f(i+1,j‐1)‐f(i,j‐1); end end end fprintf('n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐NF TABLE ‐‐‐‐‐‐‐‐') for i=1:n fprintf('n %0.2f t %0.2f',x(i),y(i)); for j=1:(n‐i) fprintf('tt %0.2f',f(i,j)); end end fprintf('‐‐‐‐‐‐‐‐‐‐‐‐‐‐TABLE ENDS‐‐‐‐‐‐‐') sum=y(1); for i=1:(n‐1) prod=f(1,i); for j=1:i prod=prod*(xp‐x(j))/(j*h); end sum=sum+prod; end fprintf(' YP=%f',sum);
  • 17. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 17 Unit 6 Integration %TRAP %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ f=inline('x.^3'); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ a=input('Enter Lower Limit,a='); b=input('Enter Upper Limit,b='); ns=1; % depends on method na=input('Enter Number of application ,na='); n=na*ns; h=(b‐a)/n; sum=0; x1=a; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=1:na sum=sum+f(x1)*1+f(x1+h)*1; % depends on method x1=(x1+h); end Area=sum*h/2; % depends on method %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ fprintf('n Area of integration=%0.2f',Area) % Solver clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ f =inline('x.^3'); a=2;b=3; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ Q = quad(f,a,b)
  • 18. NM [DR D.P.BHASKAR, SANJIVANI COLLEGE OF ENGINEERING KOPARGAON] 18 % Double Trap Integration %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ clc clear all %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ f=inline('x+y'); %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ns=1; a=1;b=3;c=0;d=2;na=2;ma=2; n=na*ns;m=ns*ma; h=(b‐a)/n; k=(d‐c)/m; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ y1=c; for j=1:m+1 x1=a; sum=0; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ for i=1:na sum=sum+f(x1,y1)+f((x1+h),y1); x1=(x1+h); end s(j)= h/2*sum; y1=y1+k; end %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ sum=0; for j=2:ma sum=sum+s(j); end %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ sum=sum*2; sum=sum+s(1)+s(m+1); sum=sum*k/2 %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ fprintf('Volume=%f',sum); %Solver Double Integration (dblquad) clc clear all f =inline('x+y') a=1;b=3;c=0;d=2; %‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ Volume=dblquad(f,a,b,c,d); fprintf(' Volume of integration=%0.2f',Volume);