Question

Calculate 1 0 , and apply the composite trapezoidal rule to numerically compute it with evenly spaced nodes 0 = x_0 < x_1 < ... < x_n = 1 where n = 10, 20, 40, 80. Compute absolute numerically errors. Please post your code in MATLAB and present your results in the table below:

n 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 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) tuppExact integration value for a=0.000000 to b= 1 .000000 is 0.693147. n Trapizoidal error error*n 2 10 0.693771 6.242226e-04 6.

%%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 Trapizoidal\t error\t error*n^2\n')
for i=1:length(n)
    N=n(i);
    %all integration values
    val=trapizoidal(func,a,b,N);
    er1=abs(val-I_ext);
    er2=er1*N^2;
    fprintf('\n\t%d \t %f \t %e \t %e.\n',N,val,er1,er2)
end
%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%    
%%Matlab function for Trapizoidal integration
function val=trapizoidal(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
    val=0;
    %splits interval a to b into N+1 subintervals
    xx=linspace(a,b,N+1);
    dx=xx(2)-xx(1); %x interval
    %loop for Riemann integration
        for i=2:length(xx)-1
            xx1=xx(i);
            val=val+dx*double(func(xx1));
        end
       val=val+dx*(0.5*double(func(xx(1)))+0.5*double(func(xx(end))));
end

%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
Calculate , and apply the composite trapezoidal rule to numerically compute it with evenly spaced nodes where n = 10...
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
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
ADVERTISEMENT