Uploaded by shankar varma

MATLAB

advertisement
NAME MALLADI VEERA SHANKAR VARMA
218EC1384
LAB 4
Q1Jwrite a MATLAB code to find the partial derivative of a function by asking the user
whether with respect to x and y.
MATLAB CODE:
k clear all
format
compact 8Y0
xY
z= input('Enter the two dimensional function fix): "%
x1 = input('enter the x value at which the derivative has to be evaluated: ' ; yl=
inputf'enter the y value at which the derivative has to be evaluated: ); z1=
subs(substz,xxl},vv1) ezsurttz,k1-2 x1+2]) f1
diffz) f1 - dif(zy) slopex
substsubstf1,x.xl}yv1}; k2,22]-mesbgridk1-2:25x1+2,0:0.5:10);
y2-y1"ones(sizet2); hold on hi=surfix2,y2,22);
set{h2, FaceColor,10.7,0.7,0.71, EdeeColor none"') telinspacel-1,1); x3=x1
y3=y1"ones(size(t)); 23=z1+slopex"t
linelx3,y3,23,color'blue'. Tinewidth ,2)
OUTPUT:-
COMMAND:
Enter the two
dimensional function
flx
-y^3
enter the x value at which the derivative has to be evaluated:
enter the y value at which the derivative has to be evaluated:
3x2
1=
3y*2
JFind the partial derivatives of Flsy)-sint/(1+v) with
respect to
x at
the
point
(1,2)
MATLAB CODE:
Ciear an
format compact
z=inputfEnter the two dimensional function fly): "%
x1 = input('enter the x value at which the derivative has to be evaluated: );
yl = inputf'enter the y value at which the derivative has to be evaluated:);
subs(subs{z.xxl)}My1)
ezsuffz.xi-2 x1+2])
dif{z)
slopex subslsubs[f1,xx1),Y.x1);
*2,22}=mesbgrldix1-2:25xd+2,0:0.5:10);
y2=y1'ones(size(z2);
hold on
hl=surf{x2,y2,22);
set{h1, FaceColor,j0.7,0.7,0.7],EdeeColor'none)
t=ipspacel-1,1;
x3-x1t;
y3=y1 "ones(sizeft);
R71+stope
linefx3,y3,23, color,'blue', Tinewidth', 2)
OUTPUT:
Figure 1
sin/ly 1
09
0.9
COMMAND:
Enter the two dimensional function figy):
sin/l1y)
enter the x value at which the derivative has to be evaluated:
enter the y value at which the derivative has to be evaluated:
1=
sin(1/3)
cos(/(y + 1)/(y + 1)
Q5) Find the partial derivatives of Fl8y)=x*3*y"3+6xy-1 with respect to y
at the point (1,1)
MATLAB CODE:
d
dear all
format compact
2
=
input('Enter the two dimensional function flxy): "
x1 = input('enter the x value at which the derivative has to be evaluated: ;
y1=
input 'enter the y value at which the derivative has to beevaluated:);
subssubstxxl)yw1)
ezsuffz k1-2 x+2])
1 = difflzy)
slopex= substsubs(f1,x,xl},Y.y1);
x2,22)-meshgridx1-2:.25:x1+2,0:0.5:10);
y2y1onessizefx2)};
hold on
h1=surffx2,y2,22);
set(h1,FaceColor,[0.7,0.7,0.71 EdaeColor' none")
tjospacel-1,1);
x3-x1+t;
y3-y1 ones(size(t);
3z1+slopex*t
line(x3,y3,23, color, blue, linewidth',2
OUTPUT::
COMMAND:
Enter the two dimensional function
flx
x3+y*3»6"(*'v}1
enter the x value at which the derivative has to be evaluated:
enter the y value at which the derivative has to be evaluated:
y1
3*y^2+6"x
Q4JFind the partial derivative of Flxyl= 4-*2-2y*2 with respect
to x at the polint (1,1) and visualize it.
MATLAB CODE:
lear all
format compact
SYDSY
z = input('Enter the two dimensional function flxy): "%
xl
=
input('enter the x
value at which the derivative has to be
yl= inputf'enter the y value at which the derivative has to be
21
subs(substzxxl).y.vl1)
SzSuffz,[x1-2 x1+2])
f1
difflzx)
sloRex subs(subs{f1,x,x1)Y,y1);
x2,22]-mestegridix1-2:.25:x1+2,0:0.5:10);
y2=y1 onessize{x2);
hold on
hi=surf{z2,y2,22);
set{hi,FaceColor',J0.7,0.7,0.71,EdeeColot'none)
Tinseacef-1,1);
x3-x1t;
y3-y1onessizeft);
23-21+slopext;
line(3,y3,23,color red', linewidth,2)
COMMAND
Enter the two dimensional function
flsy):
4x2-2y2
enter the x value at which the derivative has to be evaluated:
enter the y value at which the derivative has to be evaluated:
21
1
evaluated: '};
evaluated:"'
2x
OUTPUT:
Pigure
2
Q5JFind the partial derivative of Flsy)=4-x*2-2y*2 with respect
to y at the point (1,1).
MATLAB cODE
clear al
format compact
z = input('Enter the two dimensional function flxy): ":
xl = input('enter the x value at which the derivative has to be evaluated: } ;
yl= inputf'enter the y value at which the derivative has to be evaluated:");
z1 = subsísubsiz,x,xl),v,y1)
ezsufiz,k1-2 x1+2})
= diflzy)
slopex subs(subs{f1,xx1),v.y1);
k2,22/-meshgridfxl-2:.25:x1+2,0:0.5:10);
y2=y1 ones(size(x2);
d on
h1esurfx2,y2,2]};
setth1, FaceColor", J0.7.0.7,0.7]1. EdeeColor, none)
t-linseacel-1,;
x3xl+;
y3=yl "ones{size(t)};
z3=21+slopex*t
linetx3,y3,23,'color, red, linewidth,2)
OUTPUT
Fgure
4.2.
15
COMMAND:
Enter the two dimensional function flxy):
4-**22*y*2
enter the x value at which the derivative has to be evaluated:
1
enter the y value at which the derivative has to be evaluated:
1=
A
Download