Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168730
Image: ubuntu2004

Left Hand Riemann Sums

Type in your own f(t), a, b, and n. Then click evaluate.

var ('t') f(t)=cos(t) a=-5 b=5 n=10

Click evaluate.

def left_riemann_plot(f, a, b, n): p = plot(f, a, b, thickness=2) deltax = (b-a)/n rectops = Piecewise([[(a+j*deltax, a+(j+1)*deltax),f(a+(j+1)*deltax)] for j in range(n)]) prectops = plot(rectops, color='magenta', fill='axis', fillcolor='magenta') outline = [] for j in range(n): outline = outline + [(a+j*deltax,0), (a+j*deltax,f(a+(j+1)*deltax)), (a+(j+1)*deltax,f(a+(j+1)*deltax)), (a+(j+1)*deltax, 0)] poutline = plot(line(outline, rgbcolor='black')) show(p + prectops + poutline)

Click Evaluate.

def left_riemann_value(f, a, b, n): deltax = (b-a)/n return(sum(f(a+(j+1)*deltax)*deltax for j in range(n)))

Click Evaluate and you will see the Graph.

left_riemann_plot(f,a,b,n)

Click evaluate to see the solution.

left_riemann_value(f,a,b,n).n()
-1.75529911082289

Hope you had enjoyed this! I did not use the "my list" you had provided, however, this code works for all functions.


Thank You.