Numerically apply the composite Simpson’s rule to compute with evenly spaced nodes with n = 10, 20, 40, 80. Note that different coefficients should be placed in front of the function values at nodes with odd and even subscripts. Compute absolute errors. Please attach your MATLAB code and complete the table below:
%%Matlab code for finding integration
clear all
close all
%functions for which integration have to do
func=@(x) 1./(1+x) ;
%upper and lower limit of integrations
a=0;b=1;
%All n values
n=[10 20 40 80];
fprintf('\n\nFor the function f(x)= ')
disp(func)
%Exact integration for function
I_ext = integral(func,a,b);
fprintf('\nExact integration value for a=%f to b=%f is
%f.\n',a,b,I_ext)
%loop for finding integrations
fprintf('\n\tn \t Simpson\t error\t error*n^4\n')
for i=1:length(n)
N=n(i);
%all integration values
val=simpson(func,a,b,N);
er1=abs(val-I_ext);
er2=er1*N^4;
fprintf('\n\t%d \t %f \t %e \t
%e.\n',N,val,er1,er2)
end
%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%Matlab function for Simpson integration
function val=simpson(func,a,b,N)
% func is the function for integration
% a is the lower limit of integration
% b is the upper limit of integration
% N number of rectangles to be used
%splits interval a to b into N+1
subintervals
xx=linspace(a,b,N+1);
dx=xx(2)-xx(1); %x interval
val=(dx/3)*(double(func(xx(1)))+double(func(xx(end))));
%loop for Riemann integration
for
i=2:length(xx)-1
xx1=xx(i);
if mod(i,2)==0
val=val+(dx/3)*4*double(func(xx1));
else
val=val+(dx/3)*2*double(func(xx1));
end
end
end
%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%
Numerically apply the composite Simpson’s rule to compute with evenly spaced nodes with n = 10, 20, 40, 80. Note tha...
Calculate , and apply the composite trapezoidal rule to numerically compute it with evenly spaced nodes where n = 10, 20, 40, 80. Compute absolute numerically errors. Please post your code in MATLAB and present your results in the table below: 1 0 We were unable to transcribe this imagen Result by the composite trapezoidal rule Absolute error Absolute errorxn2 10 20 40 80 1 0 n Result by the composite trapezoidal rule Absolute error Absolute errorxn2 10 20 40...
MATLAB Create a function that provides a definite integration using Simpson's Rule Problem Summar This example demonstrates using instructor-provided and randomized inputs to assess a function problem. Custom numerical tolerances are used to assess the output. Simpson's Rule approximates the definite integral of a function f(x) on the interval a,a according to the following formula + f (ati) This approximation is in general more accurate than the trapezoidal rule, which itself is more accurate than the leftright-hand rules. The increased...