0% found this document useful (0 votes)
10 views6 pages

MATlab 4

This document discusses evaluating definite integrals using Riemann sums and area under curves. It provides code to calculate Riemann sums and defines integrals between functions to find the enclosed area. Examples are given to find the area between different curve function regions.

Uploaded by

lazzygirl2002
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)
10 views6 pages

MATlab 4

This document discusses evaluating definite integrals using Riemann sums and area under curves. It provides code to calculate Riemann sums and defines integrals between functions to find the enclosed area. Examples are given to find the area between different curve function regions.

Uploaded by

lazzygirl2002
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/ 6

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

enter the function f(x):


sin(x)
enter lower limit of x:
0
enter the upper limit of x
2*pi
number of intervals
10

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

ENTER THE Y1 REGION


x
ENTER THE Y2 REGION
x^2-2*x

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:-

You might also like