0% found this document useful (0 votes)
15 views

Matlab Assignment 4

maivsh d xjka

Uploaded by

gineethrs696
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Matlab Assignment 4

maivsh d xjka

Uploaded by

gineethrs696
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Matlab Project – 4

Name :- Gineeth.R

Registration Number :- 24BAI1017


Matlab code for Volume of solid of revolution :-
clc

clearvars

syms x ;

f = input('Enter the function:');

fL = input('Enter the interval on which the function is defined:');

yr = input('Enter the axis of rotation y=c (Enter only c value):');

iL = input('Enter the integration limits:');

Volume = pi*int((f-yr)^2,iL(1),iL(2));

disp(['Volume is:', num2str(double(Volume))])

fx = inline(vectorize(f));

xvals = linspace(fL(1),fL(2),201);

xvalsr = fliplr(xvals);

xivals = linspace(iL(1),iL(2),201);

xivalsr = fliplr(xivals);

xlim = [fL(1) fL(2)+0.5];

ylim = fx(xlim);

figure('Position',[100 200 560 420])

subplot(2,1,1)
hold on;

plot(xvals,fx(xvals),'-b','Linewidth',2);

fill([xvals xvalsr],[fx(xvals) ones(size(xvalsr))*yr],[0.8 0.8 0.8], 'FaceAlpha',0.8)

plot([fL(1) fL(2)], [yr yr], '-r','LineWidth',2);

legend('Fuction Plot','Filled Region','Axis of Rotation','Location','Best');

title('Function y=f(x) and Region');

set(gca,'XLim',xlim)

xlabel('x-axis');

ylabel('y-axis');

subplot(2,1,2)

hold on;

plot(xivals,fx(xivals),'-b','Linewidth',2);

fill([xivals xivalsr],[fx(xivals) ones(size(xivalsr))*yr],[0.8 0.8 0.8],'FaceAlpha',0.8)

fill([xivals xivalsr],[ones(size(xivals))*yr -fx(xivalsr)+2*yr],[1 0.8 0.8],'FaceAlpha',0.8)

plot(xivals,-fx(xivals)+2*yr,'-m','Linewidth',2);

plot([iL(1) iL(2)],[yr yr],'-r','Linewidth',2);

title('Rotated Region in xy-Plane');

set(gca,'XLim',xlim)

xlabel('x-axis');

ylabel('y-axis');

[X,Y,Z] = cylinder(fx(xivals)-yr,100);

figure('Position',[700 200 560 420])

Z = iL(1) + Z.*(iL(2)-iL(1));

surf(Z,Y+yr,X,'EdgeColor','none','FaceColor','flat','FaceAlpha',0.6);
hold on;

plot([iL(1) iL(2)],[yr yr],'-r','Linewidth',2);

xlabel('X−axis');

ylabel('Y−axis');

zlabel('Z−axis');

view(22,11);

Q1) Visualize and find the volume of the region in the first quadrant bounded
above by the line y=sqrt(x), below by the curve y=sec(x)tan(x), and on the left by
the y-axis, about the line y=sqrt(2).

Ans)
Graph :-
In Matlab :-

In Command Window :-
Enter the function:

sec(x)*tan(x)

Enter the interval on which the function is defined:

[0 pi/4]

Enter the axis of rotation y=c (Enter only c value):

sqrt(2)

Enter the integration limits:

[0 pi/4]

Volume is:2.3014

In Figure Window :-
Q2) Visualize and find the volume of the solid generated by revolving region
bounded by curve y=sin(x), 0<=x<= π, about the line y=c, 0<=c<=1 by taking
c=0,0.2,0.4,0.6,0.8,1. Can you identify the range/exact value of c that maximize
and minimize the volume of the solid?

Ans)
Graph :-

C=0 :-

C=0.2 :-
C=0.4 :-

C=0.6 :-
C=0.8 :-

C=1 :-
C=0.7 :-
C=0.65 :-

In Matlab :-

In Command Window :-
i) c=0 :-

Enter the function:

sin(x)

Enter the interval on which the function is defined:

[0 pi]

Enter the axis of rotation y=c (Enter only c value):

Enter the integration limits:

[0 pi]

Volume is:4.9348
In Figure Window :-

In Command Window :-
ii) c=0.2 :-

Enter the function:

sin(x)
Enter the interval on which the function is defined:

[0 pi]

Enter the axis of rotation y=c (Enter only c value):

0.2

Enter the integration limits:

[0 pi]

Volume is:2.8163

In Figure Window :-

In Command Window :-
iii) c=0.4 :-

Enter the function:

sin(x)

Enter the interval on which the function is defined:

[0 pi]

Enter the axis of rotation y=c (Enter only c value):

0.4

Enter the integration limits:

[0 pi]

Volume is:1.4874

In Figure Window :-

In Command Window :-
iv) c=0.6 :-

Enter the function:

sin(x)

Enter the interval on which the function


is defined:

[0 pi]

Enter the axis of rotation y=c (Enter only


c value):

0.6

Enter the integration limits:

[0 pi]
Volume is:0.94804

In Figure Window :-
In Command Window :-
v) c=0.8 :-

Enter the function:

sin(x)

Enter the interval on which the function is defined:

[0 pi]

Enter the axis of rotation y=c (Enter only c value):

0.8

Enter the integration limits:

[0 pi]

Volume is:1.1983

In Figure Window :-

In Command Window :-
vi) c=1 :-

Enter the function:

sin(x)

Enter the interval on which the


function is defined:

[0 pi]
Enter the axis of rotation y=c (Enter only c value):

Enter the integration limits:

[0 pi]

Volume is:2.238

In Figure Window :-
In Command Window :-
vii) c=0.7 :-

Enter the function:

sin(x)

Enter the interval on which the function is defined:

[0 pi]

Enter the axis of rotation y=c (Enter only c value):

0.7

Enter the integration limits:

[0 pi]

Volume is:0.97445

In Figure Window :-

In Command Window :-
viii) c=0.65 :-

Enter the function:

sin(x)

Enter the interval on which the


function is defined:

[0 pi]

Enter the axis of rotation y=c (Enter only c value):

0.65

Enter the integration limits:


[0 pi]

Volume is:0.93657

In Figure Window :-
Q3) Modify the above code appropriately to visualize and find the volume of the
solid of revolution by the curve y=tan(πy/4), 0<=y<=1 about the y-axis.
Ans)
Graphs :-
In Matlab :-

In Command Window :-
Enter the function:

4/pi*(atan(x))

Enter the interval on which the function is defined:

[0 1]

Enter the axis of rotation y=c (Enter only c value):

Enter the integration limits:

[0 1]

Volume is:1.2492

In Figure Window :-

---THE
END---

You might also like