Definit Integral
Definit Integral
AIM
To evaluate the definite integrals, Riemann sums and compares it. Understanding integration as Area
under the curve
To find the area of the regions enclosed by curves and visualize it.
MATLAB 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;
for k=1:n
c = a+k*dx;
d=subs(f,x,c);
value = value + d;
end
value = dx*value
ezplot(f,[a b])
z=int(f,a,b)
rsums(f, a, b)
Example
1.Evaluate f ( x )=sin ( x ) ,0 x <2 π
Command Window:
enter the function f(x):sin(x)
enter lower limit of x 0
enter the upper limit of x2*pi
number of intervals 10
z =
value =
-1.5389e-016
z =
Figure Window:
sin(x) : 0.000000
1
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6
10
sin(x) : -0.000000
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
0 1 2 3 4 5 6
128
cos(x), tan(x)
Inference
if you increase the number of rectangles the riemann sum approximate to the original value.
II To find the area of the regions enclosed by curves and visualize it.
Note: The following code will work if the input functions are polynomials(not trigonometric). We invite your suggestions for
the improvement of the MATLAB code. mail id : [email protected]
syms. Create symbolic scalar variables and functions, and matrix variables and ... Here, set can be real , positive , integer , or
rational . ... syms x y x.
double(s) converts the symbolic value s to double precision. Converting symbolic values to double precision is useful when a
MATLAB® function does not accept symbolic values.
MATLAB Code
clc
clear all
syms x y real
y1=input('ENTER THE first(f) curve');
y2=input('ENTER THE second(g) curve');
fg=figure;
ax=axes;
t=solve(y1-y2);
kokler=double(t)
n=length(kokler)
m1=min(kokler)
m2=max(kokler)
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,t(i),t(i+1))
TA= TA+abs(A)
x1 = linspace(kokler(i),kokler(i+1));
yy1 =subs(y1,x,x1);
yy2 = subs(y2,x,x1);
x1 = [x1,fliplr(x1)];
yy = [yy1,fliplr(yy2)];
fill(x1,yy,'g')
grid on
end
else
A=int(y1-y2,t(1),t(2))
TA=abs(A)
x1 = linspace(kokler(1),kokler(2));
yy1 =subs(y1,x,x1);
yy2 = subs(y2,x,x1);
x1 = [x1,fliplr(x1)];
yy = [yy1,fliplr(yy2)];
fill(x1,yy,'g')
end
Example
2. Find the area of the regions enclosed by the curves y=x 2 −2 x , y=x
Enter THE first(f) curve
x^2-2*x
Enter the second(g) curve
x
t=0 3
kokler =
0
3
n =2
m1 =0 m2 = 3
A =-9/2
TA = 9/2
Figure window
4 2 2
3. Find the area of the regions enclosed by the curves y=x − 4 x +4 , y =x
Command window
Enter the first(f) curve
x^4-4*x^2+4
Enter the second(g) curve
x^2
kokler =
-2
-1
1
2
n=4
m1 =-2
m2 =2
A =-22/15
TA =22/15
A =76/15
TA =98/15
A =-22/15
TA = 8
Figure window
,
Practice Problem
2 2
1) Find the area of the regions enclosed by the curves y=− x + 4 x , y =x
2) Find the area of the regions enclosed by the curves y=7 − 2 x 2 , y=x 2+ 4