MATLAB Code Week 4
MATLAB Code Week 4
A. Integration
→Initialization:
value = 0;
dx = (b-a)/n;
Problems:
1) Sin(x) in [0, 2 pi]
Output
enter the function f(x):sin(x)
enter lower limit of x 0
enter the upper limit of x2*pi
number of intervals10
z =
value =
-1.5389e-016
z =
Figure Window:
Output
z=
2
value =
z=
Figure Window:
3) e^x+tan(x)
Output
z=
exp(pi/4) + log(2)/2 - 1
value =
(pi*(exp(pi/4) + exp(pi/5) + exp(pi/8) + exp(pi/10) + exp(pi/20) + exp((3*pi)/20) + exp(pi/40) + exp((3*pi)/40) +
exp((7*pi)/40) + exp((9*pi)/40) + tan(pi/20) + tan((3*pi)/20) + tan(pi/40) + tan((3*pi)/40) + tan((7*pi)/40) + tan((9*pi)/40) +
(5^(1/2)*(5 - 2*5^(1/2))^(1/2))/5 + 2^(1/2) + (5 - 2*5^(1/2))^(1/2)))/40
z=
exp(pi/4) + log(2)/2 - 1
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)
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:
4) Find the area of the regions enclosed by the curves, 𝑦 = 𝑥 2 − 2𝑥, 𝑦 = 𝑥
Output
f=
9/2
kokler =
0
3
f=
9/2
5) Find the area of the regions enclosed by the curves 𝑦 = 𝑥4 − 4𝑥2 + 4, 𝑦 = 𝑥2
Output:
ASSESSMENT-03
1. Choose any two curves of your choice such that they have multiple intersection. Then find and
visualize the closed area between them.