Question

The weights for a two-point open Newton-Cotes rule are the same as in a two-point closed...

The weights for a two-point open Newton-Cotes rule are the same as in a two-point closed Newton-Cotes rule (trapezoid rule). The quadrature points are x1 = a+1/3(b-a) and x2 =a+2/3(b-a). write a matlab function to implement a two point, open newton cotes rule, and use the function to evaluate a couple of integrals.

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

Required Matlab code with explanatory comments is given below:

START CODE

function [integral] = my2ptNC(f,a,b)
%finds the integral using 2-point open
%Newton-Cotes formulae
weights=[(b-a)/2,(b-a)/2]; %weights for 2 point open NC
xvalues=[a+1*(b-a)/3,a+2*(b-a)/3]; %the x values used in NC
fvalues=f(xvalues); %evaluate function at these points
integral=sum(weights.*fvalues); %find their weighted sum
fprintf('The integral is approximately %f12 \n',integral) %show integral
end

END CODE

Sample usage:

Command Window >my2ptNC ( (x) x.^2. sin (x),0,pi); %approximate the integral The integral is approximately 7.45895112 >my2ptN

\blacksquare

Please do rate this answer positively if you found it helpful. Thanks and have a good day!

Add a comment
Know the answer?
Add Answer to:
The weights for a two-point open Newton-Cotes rule are the same as in a two-point closed...
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