How to find the left riemann sum using a for loop?
Show older comments
I need to find the left sum of a function handle f, on the interval [a,b] with n subintervals. So far what I have is:
function r=myleftsum(f,a,b,n)
r=0;
dx=(b-a)/n;
for k=1:n
c=a+k*dx;
r=r+f(c);
end
r=dx*r;
end
I think this is taking the right sum but I need the left sum. I am not sure which line to change or what will make this code take the left sum.
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics 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!