Question

Numerically apply the composite Simpson’s rule to compute  1 0 with evenly spaced nodes 0 = x_0 < x_1 < ... < x_n = 1 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:

n Result by the composite Simpsons rule Absolute error Absolute errorxn4 10 20 40 80

1 0

n Result by the composite Simpson's rule Absolute error Absolute errorxn4 10 20 40 80
0 0
Add a comment Improve this question Transcribed image text
Answer #1


Matlab code for finding integration clear all close all %functions for which integration have to do func-e (x) 1./ (1+x) tuppFor the function f(x)- (x)1./(1+x) Exact integration value for a=0.000000 to b= 1.000000 is 0.693147. n Simpson error error*n

%%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 %%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
Numerically apply the composite Simpson’s rule to compute   with evenly spaced nodes with n = 10, 20, 40, 80. Note tha...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Calculate , and apply the composite trapezoidal rule to numerically compute it with evenly spaced nodes where n = 10...

    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 demo...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT