SUNY Geneseo Department of Mathematics
Monday, November 9
Math 230 01
Fall 2015
Prof. Doug Baldwin
>> f = @(x) x * sin(x);
>> riemann( f, 0, pi, 10 )
ans =
3.1157
>> trapezoid( f, 0, pi, 8 )
ans =
3.1011
riemann( f, a, b, n )
delta = (b-a)/n
total = 0
xs = linspace(a,b,1000)
plot xs, f(xs)
hold on
for i = a : delta : b-delta % sigma
% left sum
i1 = i + delta
x = [ i, i1, i1, i, i ]
y = [ 0, 0, f(i), f(i), 0 ]
plot x, y % current rectangle
total = total + delta * f(i)
end of for
return total