2A&2B Matlab
2A&2B Matlab
2A&2B Matlab
MATLAB COMMAND:
Surf: (X, Y, Z, C) plots the coloured parametric surface defined by four
matrix arguments. The view point is specified by VIEW. The axis labels
are determined by the range of X, Y and Z, or by the current setting of
AXIS. The colour scaling is determined by the range of C, or by the
current setting of CAXIS. The scaled colour values are used as indices
into the current COLORMAP. The shading model is set by SHADING.
MATLAB CODE:
%Evaluation of Volume of solid of revolution
clear
clc
syms x
a=I(1);b=I(2);
vol=pi*int((f(x)-yr)^2,a,b);
fx=matlabFunction(f);
xv = linspace(a,b,101); % Creates 101 points from a to b
[X,Y,Z] = cylinder(fx(xv)-yr);
Z = a+Z.*(b-a); % Extending the default unit height of the
%cylinder profile to the interval of integration.
surf(Z,Y+yr,X) % Plotting the solid of revolution about y=yr
hold on;
plot([a b],[yr yr],'-r','LineWidth',2); % Plotting the line y=yr
view(22,11); % 3-D graph viewpoint specification
xlabel('X-axis');ylabel('Y-axis');zlabel('Z-axis');
output: -
Volume of solid of revolution is:
pi*(pi/4 + 1/2)
2. Find the volume of the solid generated by revolving about the X-axis the region bounded by
the curve y = √𝑥, the x-axis, and the line y= x - 2.
output
Volume of solid of revolution is:
-pi*((8*2^(1/2))/3 - 4)
3. Find the volume of the solid generated by revolving about the line y =1, the region
bounded by the curve y = √𝑥, the lines y = 1 and x = 3.
output:
Volume of solid of revolution is:
-pi*(4*3^(1/2) - 22/3)
Exp – 2B
1.
MATLAB CODE:
clc
clear
syms x y
f(x,y)=input('Enter the function f(x,y):');
p=diff(f,x); q=diff(f,y);
[ax,ay]=solve(p,q);
ax=double(ax);ay=double(ay);
r=diff(p,x); s=diff(p,y); t=diff(q,y);D=r*t-s^2;
figure
fsurf(f);
legstr={'Function Plot'};% for Legend
for i=1:size(ax)
T1=D(ax(i),ay(i));
T2=r(ax(i),ay(i));
T3=f(ax(i),ay(i));
if(double(T1)==0)
sprintf('At (%f,%f) further investigation is required',ax(i),ay(i))
legstr=[legstr,{'Case of Further investigation'}];
mkr='ko';
elseif (double(T1)<0)
sprintf('The point (%f,%f) is a saddle point', ax(i),ay(i))
legstr=[legstr,{'Saddle Point'}]; % updating Legend
mkr='bv'; % marker
else
if (double(T2) < 0)
sprintf('The maximum value of the function is f(%f,%f)=%f', ax(i),ay(i), T3)
legstr=[legstr,{'Maximum value of the function'}];% updating Legend
mkr='g+';% marker
else
sprintf('The minimum value of the function is f(%f,%f)=%f', ax(i),ay(i), T3)
legstr=[legstr,{'Minimum value of the function'}];% updating Legend
mkr='r*'; % marker
end
end
hold on
plot3(ax(i),ay(i),T3,mkr,'Linewidth',4);
end
legend(legstr,'Location','Best');
input: -
Enter the function f(x,y): x^4 + y^4 - x^2 - y^2 + 1
Output: -
ans =
ans =
ans =
ans =
ans =
ans =
ans =
ans =
input: -
Enter the function f(x,y): x^3 + 3*x*y^2 - 15*x^2 - 15*y^2 + 72*x
Output: -
ans =
ans =
ans =