Professional Documents
Culture Documents
Section: - 1
Project
Prepared by
Name ID No.
quad method
function y = fun(x) %This MATLAB function declares a function named fun.
y = x.*exp(-x/3); %This is the equation to be executed.
We insert the integral limits by Q = quad(@fun,0,5) .
trapz method
function T= funct(x,y)
n=length(x);
T=0;
for i=1:n-1
T=T+(y(i) + y(i+1))*(x(i+1) -x(i)); %Is used to calculate the
area.
end
T=T/2;
end
We insert and run x=(0:0.1:5), y = x.*exp(-x/3),funct(x,y)respectively.
For both we get the result 4.4660 when we use mathlab. When we do it using calculator we got
4.4671, and in trapz we have observed when we minimize the gap of points between x the
result becomes more precise. To show this we used x=(0:0.00001:5) and got the result 4.4670
which is closer to the one done by calculator.