Question

[Computer Exercises 5.3.1] Find approximate values for the two integrals 1 dr 0 0 Use composite Simpsons rule with an error-

please include matlab code!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code: Function1.m

clc
clear
a = 0; b = 1;
f = @(x) 4.* 1./(1 + x.^2);
n = 2; % you can also increase n
err = 1;
while err > 0.5*10^-5
h = (b - a) / (n - 1);
x = a:h:b;
wS = h/3 * [1 2*ones(1,n-2) 1] ;
wS(2:2:end) = 4*h/3 ;
IS1 = sum(f(x) .* wS);
I = quad(f, 0, 1);
err = abs(IS1 - I);
n = n + 1;
end

disp("Absolute error of f1 = "+num2str(err));
disp("Integral of f1 = "+num2str(IS1));

Output:

Absolute error of fl = 9.0199e-07 Integral of f1 = 3.1416 x >

Code: Function2.m

clc
clear
a = 0; b = 1/sqrt(2);
f = @(x) 8 * (sqrt(1 - x.^2) - x);
n = 2; % you can also increase n
err = 1;
while err > 0.5*10^-5
h = (b - a) / (n - 1);
x = a:h:b;
wS = h/3 * [1 2*ones(1,n-2) 1] ;
wS(2:2:end) = 4*h/3 ;
IS2 = sum(f(x) .* wS);
I = quad(f, 0, b);
err = abs(IS2 - I);
n = n + 1;
end

disp("Absolute error of f2 = "+num2str(err));
disp("Integral of f2 = "+num2str(IS2));

Output:

Command Window Absolute error of f2 3.3594e-06 Integral of f2-3.1416 fx >>

Add a comment
Know the answer?
Add Answer to:
please include matlab code!! [Computer Exercises 5.3.1] Find approximate values for the two integrals 1 dr 0 0 Use composite Simpson's rule with an error-Ί 10-5 [Computer Exercises 5.3.1] Fi...
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