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

Definit Integral

The document discusses evaluating definite integrals using Riemann sums and visualizing the area between curves. It provides the MATLAB syntax and code to calculate the definite integral value and approximate it using Riemann sums with varying intervals. It also includes code to find the roots of two curves, evaluate the definite integral between the roots and visualize the enclosed area.
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)
23 views

Definit Integral

The document discusses evaluating definite integrals using Riemann sums and visualizing the area between curves. It provides the MATLAB syntax and code to calculate the definite integral value and approximate it using Riemann sums with varying intervals. It also includes code to find the roots of two curves, evaluate the definite integral between the roots and visualize the enclosed area.
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/ 5

Definite Integrals and its applications

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 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.
fliplr(A) If A is a row vector, then fliplr(A) returns a vector of the
same length with the order of its elements reversed. If A
is a column vector, then fliplr(A) simply returns A.
char(X) converts array X of nonnegative integer codes into a
character array.
Description. ezplot( f ) plots a symbolic symvar( s , n ) chooses the n symbolic variables in
expression, equation, or function f . By default, s that are alphabetically closest to x and returns
ezplot plots a univariate expression or function them in alphabetical order. If s is a symbolic
over the range [–2π 2π] or over a subinterval of function, symvar(s,n) returns the input arguments
this range. of s before other variables in s .

I To evaluate the definite integrals, Riemann sums and compares 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

You might also like