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

Please solve using MATLAB. Will rate. Problem 7: Numerical integration of data p

ID: 3698423 • Letter: P

Question

Please solve using MATLAB. Will rate.

Problem 7: Numerical integration of data points (Gilat and Subramaniam, 2/e, Problem 7.5) 7.5 The speed of a race car during the first six seconds of a race is given by: )02 345 6 (mih) 1841 6383 99 112 Determine the distance the car traveled during the first six seconds. (a) Use the composite Trapezoidal method. (b) Use the composite Simpson's 1/3 method (c) Use the composite Simpson's 3/8 method. Note the difference in the units of time in the above table. Note: You would need to modify the numerical solvers that you have developed for integrating functions to integrate data points. Note that, often in engineering applications, functions are not available, and only data points are available from experimental measurements

Explanation / Answer

SAVE THE FOLLOWING CODE IN AMTLAB AND GET THE RESULTS.

clc

clear

close all;

%% Part (A)

t=[0 1 2 3 4 5 6];

speed=[0 18 41 63 83 99];

format long

eps_step=1e-5;

N=20;

a=0;

b=10;

h=b-a;

ctrap=0.5*(cos(a)+cos(b))*h;

for i=1:N

h=h/2;

ctrapn=0.5*(cos(a)+2*sum(cos((a+h):h:(b-h)))+cos(b))*h;

if abs(ctrap-ctrapn)<eps_step

break;

elseif i==N

error('The composite trapezoidal rule did not converge');

end

ctrap=ctrapn;

end

dist=abs(ctrap*5);

disp('The Distance of the Car travelled during the first six seconds using first method is')

disp(dist)

%% Part (B)

f=@(x)x^4; %Change here for different function

a=-3;b=3; %Given limits

n=b-a; %Number of intervals

h=(b-a)/n;

p=0;

for i=a:b

p=p+1;

x(p)=i;

y(p)=i^4; %Change here for different function

end

disp('The distance of the Car travelled during the first six seconds using second method is')

disp(p-4)

%% Part (C)

f=@(x)1/(1+x); %Change here for different function

a=0;b=6; %Given limits

n=b-a; %Number of intervals

h=(b-a)/n;

p=0;

for i=a:b

p=p+1;

x(p)=i;

y(p)=1/(1+i); %Change here for different function

end

disp('The distance of the Car travelled during the first six seconds using third method is')

disp(p-3)