Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168737
Image: ubuntu2004

Solids of Revolution

Scroll down the page until you see the "applet" field. Do not change the code in the cell immediately below.

Enter formulas for f(x)f(x) and g(x)g(x) and the limits aa and bb in the text fields. To redraw the solid, click Update. The solid can be rotated by dragging with the mouse.

The applet also optionally draws a "ring" used in the volume computation by the "method of rings". The "Coordinate" option gives the position of the ring. It must be chosen carefully to make sure the ring intercepts the surface.

Created by: L. Felipe Martins, [email protected]

#auto @interact def _(func1=input_box('x^2',label='f(x)=',type=str), func2=input_box('x',label='g(x)=',type=str),a=0,b=1, axis=selector(['x','y'],label='Axis of rotation:',buttons=True), ring=checkbox(default=True,label='Draw ring'), coord=input_box(0.5,label='Ring coordinate:',type=float),auto_update=False): f = lambda x: sage_eval(func1,{'x':x}) g = lambda x: sage_eval(func2,{'x':x}) g2 = plot(f,a,b,color='orange') g2 += plot(g,a,b,color='green') g2 += line([[a,g(a)],[a,f(a)]],color='gray') g2 += line([[b,g(b)],[b,f(b)]],color='gray') show(g2,figsize=4) if axis=='x': f1 = lambda t,x: x f2 = lambda t,x: f(x)*cos(t) f3 = lambda t,x: f(x)*sin(t) g1 = lambda t,x: x g2 = lambda t,x: g(x)*cos(t) g3 = lambda t,x: g(x)*sin(t) else: f1 = lambda t,x: x*cos(t) f2 = lambda t,x: x*sin(t) f3 = lambda t,x: f(x) g1 = lambda t,x: x*sin(t) g2 = lambda t,x: x*cos(t) g3 = lambda t,x: g(x) g3d = parametric_plot3d([f1,f2,f3],(0,2*pi),(a,b),color='orange',opacity=0.5) g3d += parametric_plot3d([g1,g2,g3],(0,2*pi),(a,b),color='green',opacity=0.5) if ring: r1 = lambda t,r: coord r2 = lambda t,r: r*cos(t) r3 = lambda t,r: r*sin(t) try: if axis=='x': lb = min(f(coord),g(coord)) ub = max(f(coord),g(coord)) g3d += parametric_plot3d([r1,r2,r3],(0,2*pi),(lb,ub),color='gray',opacity=1.0) else: x1 = find_root(lambda x:f(x)-coord,a,b) x2 = find_root(lambda x:g(x)-coord,a,b) lb = min(x1,x2) ub = max(x1,x2) g3d += parametric_plot3d([r2,r3,r1],(0,2*pi),(lb,ub),color='red',opacity=1.0) except ZeroDivisionError: print 'Unable to plot ring. Try changing coordinate.' print 'Ring:\nInner radius: %f\nOuter radius: %f' % (lb,ub) show(g3d)
f(x)= 
g(x)= 
Axis of rotation: 
Draw ring 
Ring coordinate: 
[removed]
[removed]
[removed]
[removed]
[removed]
interact?