Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168765
Image: ubuntu2004
# TODO: figure out a way to determine if f is an expression or callable symbolic function for the if statement. def make_coordinate_plot3d(transformation, function_variable,parameter_variables): def new_plot(f, var1_range, var2_range,**kwds): f_is_expression=True if f_is_expression: # if f is an expression, then we can use .subs. This is faster, because parametric_plot3d # can then use fast_float if len(var1_range)==3: vars=[var1_range[0], var2_range[0]] else: vars=sage.symbolic.ring.var('v1,v2') plot_func=[t.subs({function_variable:f, parameter_variables[0]:vars[0], parameter_variables[1]:vars[1]}) for t in transformation] else: # if f is not a symbolic expression or function, use the following # We could make this faster by using fast_float on the components of transformation # We need to do the function and map instead of just a list comprehension because # of python scoping; see http://lackingrhoticity.blogspot.com/2009/04/python-variable-binding-semantics-part.html def subs_func(t): return lambda x,y: t.subs({function_variable:f(x,y), parameter_variables[0]:x, parameter_variables[1]:y}) plot_func=map(subs_func,transformation) return parametric_plot3d(plot_func, var1_range, var2_range,**kwds) return new_plot
var('r,t,p')
(r, t, p)
jason_spherical_plot3d=make_coordinate_plot3d([r*cos(t)*sin(p), r*sin(t)*sin(p), r*cos(p)], function_variable=r, parameter_variables=[t,p])
jason_spherical_plot3d(2,(t,0,pi/4),(p,0,pi))
oscar_spherical_plot3d=make_coordinate_plot3d([r*cos(p)*sin(t), r*sin(p)*sin(t), r*cos(t)], function_variable=r, parameter_variables=[t,p])
var('x,y')
(x, y)
oscar_spherical_plot3d(2,(x,0,pi/4),(y,0,pi))
var('x,y,z,t')
(x, y, z, t)
cylindrical_plot3d=make_coordinate_plot3d([r*cos(t)*z, r*sin(t)*z, z], function_variable=z, parameter_variables=[r,t])
cylindrical_plot3d(t,(r,0,3),(t,0,3*pi))