0% found this document useful (0 votes)
6 views

matlab final print

mathlab codes

Uploaded by

biscuit7237
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

matlab final print

mathlab codes

Uploaded by

biscuit7237
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Tangent line

syms x
y=input("enter the function f in terms of x:")
x1=input("enter x value at which tangent;")
ezplot(y,[x1-2 x1+2])
hold on
y_derivative=diff(y,x)
slope=subs(y_derivative,x,x1)
y1=subs(y,x,x1)syms
plot(x1,y1,'r:*')
tgt_line=slope*(x-x1)+y1
h=ezplot(tgt_line,[x1-2 x1+2])
set(h,'color','r')
hold off

clc
syms x
f(x)=x^2:
yr=0
I=[1,4]
a=I(1);b=I(2)
vol=pi*int((f((x)-yr)^2,a,b);
disp(vol);
fx=matlabFunction(f)
xv=linspace(a,b,101);
[X,Y,Z]=cylinder(fx(xv));
Z=a+Z*(b-a)
surf(Z,Y+yr,X)
hold on
plot([a,b],[yr,yr],'-r','LineWidth',2)

clc
clear all
syms x y lam real
f=input("Enter the function to be maximized in terms of x and y:")
g=input("Enter the constraint function in terms of x and y:")
[alam,ax,ay]=solve(jacobian(f-lam*g,[x y lam]))
t=subs(f,{x,y},{ax,ay})
for i=1:1:size(t)
figure
sprintf("The point(x,y) is (%d,%d)",double(ax(i)),double(ay(i)))
sprintf("The value of the function is %d",double(t(i)))
[X1,Y1]=meshgrid(double(ax(i))-3:.2:double(ax(i))+3,double(ay(i))-3:.2:double(ay(i))+3)
zfun=@(x,y)eval(vectorize(f))
Z1=zfun(X1,Y1)
contour(X1,Y1,Z1,75)
hold on
h=ezplot(g,[double(ax(i))-3,double(ax(i))+3])
set(h,'Color',[1,0,7,0,9])
plot(double(ax(i)),double(ay(i)),'r.','MarkerSize',12)
End
VECTOR DIFFERENTIATION AND INTEGRATION
clc
clear all
syms x y
f=input('enter the function f(x,y)');
F=gradient(f);
p=inline(vectorize(F(1)),'x','y');
q=inline(vectorize(F(2)), 'x','y');
x=linspace(-2,2,10);
y=x;
[X,Y]=meshgrid(x,y);
U=p(X,Y);
V=q(X,Y);
quiver(X,Y,U,V,1)
hold on
ezcontour(f,[-2 2])

FIND THE LOCAL EXTREME VALUES FOR ANY THREE DIFFERENT FUNCTIONS

clc
clear all
syms x y real
f=input('Enter the function f(x,y)');
fx=diff(f,x);fy=diff(f,y)
[ax ay]=solve(fx,fy);
fxx=diff(fxx,x); fxy=diff(fx,y); fyy=diff(fy,y);
D=fxx*fyy-fxy^2;
for i=1:1:size(ax)
figure
T1=subs(subs(D,x,ax(i)),y,ay(i));
T2=subs(subs(fxx,x,ax(i)),y,ay(i));
T3=subs(subs(f,x,ax(i)),y,ay(i));
if(double(T1)==0)
sprintf('The point(x,y) is (%d,%d) and need further investigation',double(ax(i)),double(ay(i)))
elseif(double(T1)<0)
sprintf('The point(x,y) is (%d,%d) is saddle point',double(ax(i)),double(ay(i)))
else
if(double(T2)<0)
sprintf('The maximum point(x,y) is (%d,%d)',double(ax(i)),double(ay(i)))
sprintf('The value of the function is %d',double(T3))
else
sprintf('The minimum point (x,y) is (%d,%d)',double(ax(i)),double(ay(i)))
sprintf('The value of the function is %d',double(T3))
end
end
ezsurf(f,[double(ax(i))-2,double(ax(i))+2,double(ay(i))-2,double(ay(i))+2]);
hold on
plot3(double(ax(i)),double(ay(i)),double(T3),'r*','MarkerSize',15);
end
VECTOR DIFFERENTIATION AND INTEGRATION

clear
clc
syms x y t
F=input('Enter the vector function M(x,y)i+N(x,y)j in the form [M N]:');
M(x,y)=F(1); N(x,y)=F(2);
r=input('Enter the parametric form of the curve C as [r1(t) r2(t)]: ');
r1=r(1);r2=r(2);
P=M(r1,r2);Q=N(r1,r2);
fr=diff(r,t);
F1=sum([P,Q].*dr);
T=input('Enter the limits of integration for t [t1,t2]:');
t1=T(1);t2=T(2);
LHS=int(F1,t,t1,t2);
yL=input('Enter the limits for y in terms of x: [y1,y2]: ');
xL=input('Enter limits for x as constants: [x1,x2]: ');
y1=yL(1);y2=yL(2);x1=xL(1);x2=xL(2);
F2=diff(N,x)-diff(M,y);
RHS=int(int(F2,y,y1,y2),x,x1,x2);
if(LHS==RHS)
disp('LHS of Greens theorem=')
disp(LHS)
disp('RHS of Greens theorem=')
disp(RHS)
disp('Hence Greens theorem is verified.');

clc
clear all
syms x y z real
F=input('enter the vector as i,j and k order in vector form:')
curl_F=curl(F,[x,y,z])
div_F=divergence(F,[x,y,z])
Local extreme
syms x real
f=input("enter")
f=x diff(f,x)
c= solve(fx)
cm=min(double(c))
cmax =max(double(c))
ezplot(f, [cm-2,cmax+2])
hold on
fxx= diff(fx,x)
for i=1:1:size(c)
t1= subs (fxx,x,c(i))
t3= subs(f,x,c(1))
if (double(t1)==0)
sprintf('the point x is %d inflextion point', double(c(i)))
else
if(double(t1)<0)
sprintf('the maximum point x is %d', double(c(1)))
sprintf('value of function is %d', double(t3))
else
sprintf('the minimum point x is %d', double(1))
sprintf('value of function is %d", double(t3))
end

Area b/w curves


syms x
yl input('ENTER THE Y1 REGION VALUE')
y2=input('ENTER THE Y2 REGION VALUE')
fg=figure;
ax=axes;
ezl = ezplot(char(y1));
hold on
ex2=ezplot(char(y2));
hold on
t=solve(y1-y2);%(Y1-Y2)=0
feint(y1-y2,t(1),(2))
kokler double(t)
x1=linspace(kokler (1), kokler(2));
yy1=subs (y1,x,x1);
x1=[x1,x1];
yy=[yy1,yy2];
fill(x1,yy,'g')
Volume of solid revolution
syms x
f(x)=x^2-4*x+5;
yr=0;
i=[1,4];
a=i(1);b=i(2);
vol=pi*int((f(x)-yr)^2,a,b);
disp("VOLUME OF SOLID OF REVOLUTION IS:");
disp(vol);
fx-matlabFunction(f) xv=linspace(a,b,101);
[x,y,z]=cylinder(fx(xv));
z=a+z.*(b-a);
surf(z,y+yr,x) plot([a,b], [yr, yr], '-r', 'LineWidth', 2);
hold on
plot([a,b],[yr,yr],’-r’,’LineWidth’,2);

FIND EXTREMES VALUES OF ANY THREE DIFFERENT FUNCTION USING LAGRANGIAN METHOD OF
MULTIPLIER
clc
clear all
syms x y lam real
f=input('enter fn');
g=input('enter sub'); [alam,ax,ay]=solve(jacobian(f-lam*g,[x y lam]));
t=subs(f,{x,y}, {ax,ay});
for i=1:1:size(t)
figure
sprintf('the point(x,y) is (%d,%d)', double ( ax(i)), double(ay(i)))
sprintf('the value of the function is %d', double(t(i))) [X1,Y1]=meshgrid(double(ax(i))-3:.2:double(ax(i))+3,double(ay(i))-
3:.2:double(ay(i))+3); zfun=@(x,y)eval(vectorize(f));
Z1=zfun(X1,Y1);
contour(X1,Y1,Z1,75)
hold on
h=ezplot(g.[double(ax(i))-3,double(ax(i))+3]);
set(h, 'color',[1,0.7.0.9])
plot(double(ax(i)),double(ay(i)),'r.','MarkerSize', 12)
end

You might also like