MATlab 4
MATlab 4
Definite Integrals
Aim:
• To evaluate the definite integrals, Riemann sums and
compares it.
• To find the area of the regions enclosed by curves and
visualize it.
Riemanns Sum
CODE
clc
clear all
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)
value=0;
dx=(b-a)/n; %width
for k=1:n
c= a+k*dx; %right end points
d=subs(f,x,c);%substitued c in x in func f(height)
value=value+d;
end
value=dx*value
fplot(f,[a b])
%z=int(f,a,b)
rsums(f,a,b)
Command window
z =
value =
Figure
Area under graphs
Code
clc
clear all
syms x y
y1=input('ENTER THE Y1 REGION');
y2=input('ENTER THE Y2 REGION');
f1=fplot(y1);
hold on
f2=fplot(y2);
hold on
t=solve(y1-y2);
f=int(y1-y2,t(1),t(2))
kok=double(t)
x1=linspace(kok(1),kok(2));
yy1=subs(y1,x,x1);
yy2=subs(y2,x,x1);
x1=[x1,x1]
yy=[yy1,yy2]
fill(x1,yy,'g')
grid on
hold off
Output
f =
9/2
FIGURE
Practice problems:
1.Find the area of the regions enclosed by the curves
2.Find the area of the regions enclosed by the curves
1. Output
ENTER THE Y1 REGION
-x^2+4*x
ENTER THE Y2 REGION
x^2
f =
8/3
kok =
0
2
Figure:-
2. Output
ENTER THE Y1 REGION
7-2*x^2
ENTER THE Y2 REGION
x^2+4
f =
kok =
-1
1
Figure:-