Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168699
Image: ubuntu2004
def LRAM(f, width, start, end): return width*sum(f(x) for x in [start..end-width,step=width]) def RRAM(f, width, start, end): return width*sum(f(x) for x in [start+width..end,step=width])
def f(x): return 1/e^x width= 1/8 start=0 end=4
LRAM(f,width,start,end)
RRAM(f,width,start,end)
def LRAMarea(f,width,start,end): L=[[start,0],[start,f(start)],[start+width,f(start)],[start+width,0]] if start+width==end: return polygon(L) return polygon(L) + LRAMarea(f,width,start+width,end) def RRAMarea(f,width,start,end): L=[[start,0],[start,f(start+width)],[start+width,f(start+width)],[start+width,0]] if start+width==end: return polygon(L) return polygon(L) + RRAMarea(f,width,start+width,end)
LRAMarea(f,width,start,end)+plot(f,(x,start,end), color='red')
RRAMarea(f,width,start,end)+plot(f,(x,start,end), color='red')
f(x) = sin(x) @interact def _(width=pi/12,start=0,end=pi,RAM=['None','Left','Right']): show(f) graph = plot(f,(x,start,end), color='red') if RAM == 'Left': graph += LRAMarea(f,width,start,end) print 'Approximate area:',LRAM(f,width,start,end).n() elif RAM == 'Right': graph += RRAMarea(f,width,start,end) print 'Approximate area:',RRAM(f,width,start,end).n() if RAM != 'None': print 'Actual area:',integral(f,x,start,end).n() show(graph,aspect_ratio=1)
width 
start 
end 
RAM 
[removed]
[removed]
[removed]
[removed]