## Question

###### Please help with MATLAB problem Problem 5 (15 points) Determine the following integral Icos (sin (e"))...

please help with MATLAB problem

## Answers

%given function

function y=myFunction(x)

y=sin(cos(e.^x));

end

%functon to find the integral

function Int=myIntegral(f,a,b)

%max no. of iterations

maxIt=20;

%allowed relative error

maxError=1e-8;

%variable for convergence

con=0;

%loop variable

kk=1;

%storing each level integral value

T=zeros(maxIt,maxIt);

%multiple of 2

N=2;

%sub intervals

h=(b-a)/2;

%T(1,1) by trapezoidal rule

T(1,1)=h*(f(a)+2*f(a+h)+f(b))/2;

%loop to find the integral value

while ~con && kk<=maxIt

%increment kk

kk=kk+1;

%increment N by factor of 2

N=2*N;

%calculate new sub intervals

h=(b-a)/N;

%for holding sum

oddSum=0;

%loop

for mm=1:2:(N-1)

oddSum=oddSum+(f(a+mm*h));

end

%find T(kk,1)

T(kk,1)=T(kk-1,1)/2+h*oddSum;

%Romberg method

for mm=2:kk

T(kk,mm)=(4^(mm-1)*T(kk,mm-1)-T(kk-1,mm-1))/(4^(mm-1)-1);

end

%check for convergence

con=abs(T(kk,kk)-T(kk,kk-1))<=maxIt*abs(T(kk,kk));

end

%check if integral value converged

if con

Int=T(kk,kk); //integral value

end

end

%call myIntegral

I=myIntegral(@myFunction,0,4)