0% found this document useful (0 votes)
180 views4 pages

BMAT101P Lab Assignment 2

The document provides instructions for performing integration, finding areas between curves, and calculating volumes of revolution using MATLAB. It includes: 1) MATLAB syntax for indefinite, definite and area integration between curves using commands like int() and rsums(). 2) A process for calculating the area between two curves by solving for their intersections, integrating between points, and plotting filled polygons. 3) Commands for generating solids of revolution given a function, axis of rotation, and limits of integration and visualizing the solid and associated regions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
180 views4 pages

BMAT101P Lab Assignment 2

The document provides instructions for performing integration, finding areas between curves, and calculating volumes of revolution using MATLAB. It includes: 1) MATLAB syntax for indefinite, definite and area integration between curves using commands like int() and rsums(). 2) A process for calculating the area between two curves by solving for their intersections, integrating between points, and plotting filled polygons. 3) Commands for generating solids of revolution given a function, axis of rotation, and limits of integration and visualizing the solid and associated regions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Calculus Lab Assignment 2

Experiment 3

Integration: Indefinite, definite and Area between the curves


MATLAB Syntax used:
int(f,v) uses the symbolic object v as the
variable of integration, rather than the
variable determined by symvar
rsums(f, [a, b]) rsums(f, a, b) and rsums(f, [a,
b]) approximates the integral
for x from a to b.
fill(X,Y,C) fill(X,Y,C) creates filled polygons from
the data in X and Y with vertex color
specified by C.
char(X) converts array X of nonnegative integer
codes into a character array.

A. Integration

i) Inbuilt MATLAB function:


syms x
f=input('enter the function f(x):');
a=input('enter lower limit of x ');
b=input('enter the upper limit of x');
n=input('number of intervals');
z=int(f,a,b) % direct evaluation

ii) As a sum of rectangles by using rsums command :

→Initialization:
value = 0;
dx = (b-a)/n;

→ sum of the function values at all the right points


for k=1:n
c = a+k*dx;
d=subs(f,x,c);
value = value + d;
end
→ value of the sum* length of the sub interval is the approx. value of the integral
ivalue = dx*value
ezplot(f,[a b])

→ Taking mid point function values


rsums(f, a, b)
Problems:
1) Sin(x) in [0, 2 pi]

2) e^x+tan(x)

B. Area between the curves:


clc
clear all
close all
syms x
y1=input('ENTER THE Y1 REGION VALUE');
y2=input('ENTER THE Y2 REGION VALUE');
t=solve(y1-y2); %(Y1-Y2=0)
po=double(t)
poi=sort(po)
n=length(poi)
m1=min(poi)
m2=max(poi)

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)

%iii) Creating a polygon:

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

Experiment 4: Volume of Solid of Revolution

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

You might also like