BMAT101P Lab Assignment 2
BMAT101P Lab Assignment 2
Experiment 3
A. Integration
→Initialization:
value = 0;
dx = (b-a)/n;
2) e^x+tan(x)
ez1=ezplot(y1,[m1-1,m2+1])
hold on
TA=0
ez2=ezplot(y2,[m1-1,m2+1])
if n>2
for i=1:n-1
A=int(y1-y2,poi(i),poi(i+1))
TA= TA+abs(A)
x1 = linspace(poi(i),poi(i+1))
yy1 =subs(y1,x,x1)
yy2 = subs(y2,x,x1)
xx = [x1,fliplr(x1)]
yy = [yy1,fliplr(yy2)]
fill(xx,yy,'g')
grid on
end
else
A=int(y1-y2,poi(1),poi(2))
TA=abs(A)
x1 = linspace(poi(1),poi(2));
yy1 =subs(y1,x,x1)
yy2 = subs(y2,x,x1)
xx = [x1,fliplr(x1)]
yy = [yy1,fliplr(yy2)]
fill(xx,yy,'g')
end
Problems:
3) Find the area of the regions enclosed by the curves, 𝑦 = 𝑥 2 − 2𝑥, 𝑦 = 𝑥
4) Find the area of the regions enclosed by the curves 𝑦 = 𝑥 4 − 4𝑥 2 + 4, 𝑦 = 𝑥 2
clc
clear all
close all
%%
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));
sprintf('Volume is %3f ', double(Volume))
%% Shading the area between the axis of rot. and function
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),'k-','LineWidth',2);
plot([fL(1) fL(2)],[yr yr],'r-','LineWidth',2);
fill([xivals xivalsr],[fx(xivals) ones(size(xivalsr))*yr],[0.8 0.8 0.8],'FaceAlpha',0.8)
%% Marking the axis
%plot([fL(1) fL(2)],[yr yr],'r-','LineWidth',2);
legend('Function Plot','Axis of Rotation', 'Filled Region','Location','Best');
title('Function y=f(x) and Region');
set(gca,'XLim',xlim)
xlabel('x−axis');
ylabel('y−axis');
%% Plotting reflection of the curve about the axis of rot
subplot(2,1,2)
hold on;
plot(xivals,fx(xivals),'b-','LineWidth',2);
plot([iL(1) iL(2)],[yr yr],'r-','LineWidth',2);
fill([xivals xivalsr],[fx(xivals) ones(size(xivalsr))*yr],[0.8 0.8 0.8],'FaceAlpha',0.8)
plot(xivals,-fx(xivals)+2*yr,'m-','LineWidth',2);
fill([xivals xivalsr],[ones(size(xivals))*yr -fx(xivalsr)+2*yr],[1 0.8 0.8],'FaceAlpha',0.8)
title('Rotated Region in xy−Plane');
set(gca,'XLim',xlim)
xlabel('x−axis');
ylabel('y−axis');
%% Solid
[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(21,11);
Problems:
5) Find the volume of the solid generated by revolving the region bounded by 𝑦 =
√𝑥, 𝑜 ≤ 𝑥 ≤ 4 about the line 𝑦 = 1
6) Find the volume of the solid generated by revolving the region bounded by 𝑦 =
sin x, 𝑜 ≤ 𝑥 ≤ 𝜋 about the line 𝑦 = c, 𝑜 ≤ c ≤ 1, c = 0,0.2,0.4.0.6,0.8,1.0. Can you
identify the range or exact value of c that minimize and maximize the volume of the
solid?
7) Modify the above code appropriately to visualize the volume of the solid generated by
𝜋y
revolving the region bounded by 𝑦 = tan ( ) , 𝑜 ≤ y ≤ 1 about the 𝑦-axis
4