Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use function myinteg for a simple analysis of the numerical integration by trape

ID: 3569082 • Letter: U

Question

Use function myinteg for a simple analysis of the numerical integration by trapezoidal rule. Assume that the built in Matlab function quad calculates the exact value of the integral. Calculate the integral of the humps function between a = 0 and b = 1 using myinteg and quad functions and produce the following table: ''error'' is the absolute value of the difference between the integral produced by the function myinteg and the integral produced by the built in Matlab function quad. Find out the minimal number of intervals n min, for which the error is less than 5.10^-6. Note that the function quad requires function handle which is obtained by Matlab command: H_humps = @humps;

Explanation / Answer

clear all
clc

f=@(x) (1./((x-0.3).^2+0.01))+(1./((x-0.9).^2+0.04))-6;
err=1;
itr=50;
count=1;
while err>=1e-6 && itr<=10000

itr
result_quad=quad(f,0,1,itr);
result_myinteg=myinteg(0,1,itr);
err=abs(result_myinteg-result_quad);
table(count,1)=itr;
table(count,2)=0;
table(count,3)=1;
table(count,4)=result_myinteg;
table(count,5)=result_quad;
table(count,6)=err;
itr=itr+100;
count=count+1;
end
disp(table)