Help to simsons rule
2 views (last 30 days)
Show older comments
I need to solve the integral of exp(x) with the limits 1 to 2 The corect anwser is 4.67077
I wanna use this method, but I'm not sure how to change my own values over in the script.
figure, ezplot('sin(x)', [0, pi]), hold on
x = 0:.01:1;
plot(pi*x, 1 - 4*(x-.5).^2, 'r')
approx = zeros(1, 7); %initialize vector of results
for j = 1:7
n = 2^j;
x = pi*(0:1/n:1);
weights = [1,2*ones(1,n-1)+2*mod([1:n-1],2),1] ;
approx(j) = pi/(3*n)*sin(x)*weights';
end
disp('Using Simpson Rule')
disp(' n Approximation')
for j = 1:7
disp(['n = ', num2str(2^j, '%d'), ' ', num2str(approx(j), '%1.10f')])
end
I wanna use this method because it gives a n=2 4 8 16... and I have another script that can give me the error if I can just make this work. Please help me!
0 Comments
Answers (0)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!