2A&2B Matlab

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

EXPERIMENT 2A&2B

NAME: Anand Kholwadiya


REG NO: 21BEC2166
CLASS SLOT: L9 + L10
FACULTY: Ezhilmaran.D
Exp – 2A
(1)
AIM:
Find the volume of the solid generated by revolving about the x axis
the region bounded by the curve y= 4/(x^2+4), the x axis, and the
lines x  0 and x  2

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

f(x)=(4/(x^2+4)); % Given function

yr=0; % Axis of revolution y=yr

I=[0,2]; % Interval of integration

a=I(1);b=I(2);

vol=pi*int((f(x)-yr)^2,a,b);

disp('Volume of solid of revolution is: ');

disp(vol); % Visualization if solid of revolution

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.

%Evaluation of Volume of solid of revolution


clear
clc
syms x
f(x)=sqrt(x); % Given function
yr=0; % Axis of revolution y=yr
I=[0,2]; % Interval of integration
a=I(1);b=I(2);
vol=pi*int((f(x)-yr)^2,a,b);
disp('Volume of solid of revolution is: ');
disp(vol); % Visualization if solid of revolution
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*((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.

%Evaluation of Volume of solid of revolution


clear
clc
syms x
f(x)=sqrt(x); % Given function
yr=1; % Axis of revolution y=yr
I=[1,3]; % Interval of integration
a=I(1);b=I(2);
vol=pi*int((f(x)-yr)^2,a,b);
disp('Volume of solid of revolution is: ');
disp(vol); % Visualization if solid of revolution
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*(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 =

'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'

2. f (x, y) = x^3 + 3*x*y^2 - 15x^2 - 15y^2 + 72x


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^3 + 3*x*y^2 - 15*x^2 - 15*y^2 + 72*x

Output: -
ans =

'The maximum value of the function is f(4.000000,0.000000)=112.000000'

ans =

'The minimum value of the function is f(6.000000,0.000000)=108.000000'

ans =

'The point (5.000000,-1.000000) is a saddle point'


ans =

'The point (5.000000,1.000000) is a saddle point'

You might also like