Matlab (Da)
Matlab (Da)
Matlab (Da)
YUKTHI ABHINAV
REG. NO- 24BLC1118
SLOT: F2+TF2
r=1;
for k=1:1:size(ax)
if ((imag(ax(k))==0)&&(imag(ay(k))==0))
ptx(r)=ax(k);
pty(r)=ay(k);
r=r+1;
end
end
a1=max(double(ax))
a2=min(double(ax))
b1=max(double(ay))
b2=min(double(ay))
ezsurf(f,[a2-.5,a1+.5,b2-.5,b1+.5])
colormap('summer');
shading interp
hold on
%% Finding the maximum and minimum values of the function and their
visulaization
for r1=1:1:(r-1)
T1=subs(subs(D,x,ptx(r1)),y,pty(r1))
T2=subs(subs(fxx,x,ptx(r1)),y,pty(r1))
if (double(T1) == 0)
sprintf('The point (x,y) is (%d,%d) and need further investigation',
double(ptx(r1)),double(pty(r1)))
elseif (double(T1) < 0)
T3=subs(subs(f,x,ptx(r1)),y,pty(r1))
sprintf('The point (x,y) is (%d,%d) a saddle point',
double(ptx(r1)),double(pty(r1)))
plot3(double(ptx(r1)),double(pty(r1)),double(T3),'b.','markersize',30);
else
if (double(T2) < 0)
sprintf('The maximum point(x,y) is (%d, %d)',
double(ptx(r1)),double(pty(r1)))
T3=subs(subs(f,x,ptx(r1)),y,pty(r1))
sprintf('The value of the function is %d', double(T3))
plot3(double(ptx(r1)),double(pty(r1)),double(T3),'r+','markersize',30);
else
sprintf('The minimum point(x,y) is (%d, %d)',
double(ptx(r1)),double(pty(r1)))
T3=subs(subs(f,x,ptx(r1)),y,pty(r1))
sprintf('The value of the function is %d', double(T3))
plot3(double(ptx(r1)),double(pty(r1)),double(T3),'m*','markersize',30);
end
end
end
EXAMPLE1-
Input:
Enter the function: = 2x3+xy^2+5x2+y2
Output:
Enter the function f(x,y): 2*x^3+x*y^2+5*x^2+y^2
a1 =
0
a2 =
-1.6667
b1 =
2
b2 =
-2
ans =
'The minimum point(x,y) is (0, 0)' T3 =
0
ans =
'The value of the function is 0' T3 =
3
ans =
'The point (x,y) is (-1,-2) a saddle point' T3 =
3
ans =
'The point (x,y) is (-1,2) a saddle point' ans =
'The maximum point(x,y) is (-1.666667e+00, 0)' T3 =
125/27
ans =
'The value of the function is 4.629630e+00'
EXAMPLE2-
Input:
Enter the function: f(x,y)=2(x2-y2)-x4+y4
Output:
Enter the function f(x,y): 2*(x^2-y^2)-x^4+y^4
a1 =
1
a2 =
-1
b1 =
1
b2 =
-1
T3 = 0
ans =
'The point (x,y) is (0,0) a saddle point' ans =
'The maximum point(x,y) is (-1, 0)' T3 =
1
ans =
'The value of the function is 1'
ans =
'The maximum point(x,y) is (1, 0)' T3 =
1
ans =
'The value of the function is 1' ans =
'The minimum point(x,y) is (0, -1)' T3 =
-1
ans =
'The value of the function is -1' ans =
'The minimum point(x,y) is (0, 1)' T3 =
-1
ans =
'The value of the function is -1' T3 =
0
ans =
'The point (x,y) is (-1,-1) a saddle point' T3 =
0
ans =
'The point (x,y) is (1,-1) a saddle point' T3 =
0
ans =
'The point (x,y) is (-1,1) a saddle point' T3 =
0
ans =
'The point (x,y) is (1,1) a saddle point'
(2)EVALUATING VOLUME UNDER THE SURFACES
CODE for example 1-
clc
clear all
syms x y z
vol=8*int(int(sqrt(1-x^2-y^2),y,0,sqrt(1-x^2)),x,0,1)
viewSolid(z,0+0*x*y,sqrt(1-x^2-y^2),y,0+0*x,sqrt(1-x^2),x,0,1);
axis equal; grid on;
1 √1− x2
V =8∫ ∫ √1−x 2− y 2 dy dx .
0 0
Output:
vol =
(4*pi)/3
0.8
0.6
z
0.4
0.2
0
0
1
0.5
0.5
1 0
y
x
216/35
20
15
10
z
5 0
1
0 2
0 3
0.5
1
1.5 4
2 x
y
EXAMPLE1-
Matlab code
syms x y z
sol = int(int(int(6*x*z,y,0,x+z),x,0,z),z,0,1)
EXAMPLE2-
❑
Sol
Matlab code
syms x y z
sol = int(int(int(6*x*y,z,0,1+x+y),y,0,sqrt(x)),x,0,1)
viewSolid(z,0+0*x*y,1+x+y,y,0+0*x,sqrt(x),x,0,1);
axis equal; grid on;
EXAMPLE1-
Inference:
The gradient vectors are orthogonal to the contours.
EXAMPLE2-
Find (a) the curl and (b) the divergence of the vector field.
Matlab code
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])
Output: