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.
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
Sample usages:
Please do rate this answer positively if you found it helpful. Thanks and have a good day!
Get Answers For Free
Most questions answered within 1 hours.