I have a function which is supposed to calculate Riemann sums, here it is:
import sympy as sym
x = sym.Symbol('x')
def left_riemann_sum(f, lower_bound, list):
area = 0
cur_val = lower_bound
for x in list:
height = eval(f(cur_val))
width = x - cur_val
print("cal area for height: " + str(height) + " and width: " + str(width))
area = area + height * width
cur_val = x
return area
the problem is that eval(f(cur_val)) gives wrong value
when run this function with this params:
print('left sum: ' + str(left_riemann_sum(f1, 3, [6.5, 10])))
and for this function:
def f1(x):
return '-10*x**2+3*x+6'
it appears the heights are: -397 and -964 while it supposed to be -75 and -397. It looks like it skips first runs or so, I can't figure it out.