Matlab 02
Matlab 02
Matlab 02
1) if then find
syms x y f=x^3+3*x*y^2-15*x^2-15*y^2+72*x
f =
diff(f,x)
ans =
diff(f,y)
ans =
diff(f,x,2)
ans =
diff(f,y,2)
ans =
diff(f,x,y)
ans =
t =diff(q,y); D=r*t-s^2;
for i=1:size(ax)
T1=subs(D,{x,y},{ax(i),ay(i)});
T2=subs(r,{x,y},{ax(i),ay(i)}); T3=subs(f,{x,y},{ax(i),ay(i)}); if
(double(T1) == 0) sprintf('At (%f,%f) further investigation is
required', ax(i),ay(i)) elseif (double(T1) < 0)
sprintf('The point (%f,%f) is a saddle point', ax(i),ay(i)) else
if (double(T2) < 0) sprintf('The maximum
value of the function is f(%f,%f)=
%f',ax(i),ay(i),double(T3)) else
sprintf('The minimum value of the function is
f(%f,%f)=%f',ax(i),ay(i),double(T3)) end end
end
ans =
'The point (0.000000,0.000000) is a saddle point' ans
=
'The maximum value of the function is f(-1.000000,0.000000)=1.000000'
ans =
'The maximum value of the function is f(1.000000,0.000000)=1.000000'
ans =
'The minimum value of the function is f(0.000000,-1.000000)=-1.000000'
ans =
'The minimum value of the function is f(0.000000,1.000000)=-1.000000'
ans =
'The point (-1.000000,-1.000000) is a saddle point' ans
=
'The point (1.000000,-1.000000) is a saddle point' ans
=
'The point (-1.000000,1.000000) is a saddle point' ans
= 'The point (1.000000,1.000000) is a saddle point'
2
ans =
'The maximum value of the function is f(0.000000,0.000000)=1.000000'
ans =
'The minimum value of the function is f(-0.707107,-0.707107)=0.500000'
ans =
'The minimum value of the function is f(0.707107,-0.707107)=0.500000'
ans =
'The minimum value of the function is f(-0.707107,0.707107)=0.500000'
ans =
'The minimum value of the function is f(0.707107,0.707107)=0.500000'
ans =
'The point (-0.707107,0.000000) is a saddle point'
ans =
'The point (0.707107,0.000000) is a saddle point'
ans =
'The point (0.000000,-0.707107) is a saddle point'
ans =
'The point (0.000000,0.707107) is a saddle point'
1
4)Find the Gradient of the function
syms x y
f=input( 'Enter the function f(x,y):'); grad=gradient(f,
[x,y])
grad =
f1=diff(f,x);
f2=diff(f,y);
P = inline(vectorize(f1), 'x', 'y');
Q = inline(vectorize(f2), '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)
axis on
xlabel('x')
ylabel('y')
hold on
ezcontour(f,[-2 2])
1
x=-4:0.5:4;
y=x;
[X Y]=meshgrid (x,y);
Div=divergence(X,Y,X.*Y, X.^2);
figure
pcolor(X,Y,Div);
shading interp
hold on;
quiver(X,Y, X.*Y, X.^2,'Y');
hold off;
colormap copper
title('Vector field of F(x,y)=[xy,x^2]');
1
syms x y z real f =
[y*z, 3*x*z, z];
____________THANK YOU____________