Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
590 views
# 3D Graphing - from: # http://doc.sagemath.org/html/en/tutorial/tour_plotting.html # Use plot3d to graph a function of the form z=f(x,y) x, y = var('x,y') plot3d(x^2 + y^2, (x,-2,2), (y,-2,2))
3D rendering not yet implemented
# Alternatively, you can use parametric_plot3d to graph a parametric surface where each of x,y,z is determined # by a function of one or two variables (the parameters, typically u and v). The previous plot can be expressed # parametrically as follows: u, v = var('u, v') f_x(u, v) = u f_y(u, v) = v f_z(u, v) = u^2 + v^2 parametric_plot3d([f_x, f_y, f_z], (u, -2, 2), (v, -2, 2))
3D rendering not yet implemented
# The third way to plot a 3D surface in Sage is implicit_plot3d, which graphs a contour of a function like # f(x,y,z)=0 (this defines a set of points). We graph a sphere using the classical formula: x, y, z = var('x, y, z') implicit_plot3d(x^2 + y^2 + z^2 - 4, (x,-2, 2), (y,-2, 2), (z,-2, 2))
3D rendering not yet implemented
# Here are some more examples ... # (see Wikipedia for additional explanations of Whitney's umbrella, Cross cap, etc.) # Yellow Whitney’s umbrella: u, v = var('u,v') fx = u*v fy = u fz = v^2 parametric_plot3d([fx, fy, fz], (u, -1, 1), (v, -1, 1), frame=False, color="yellow") # Cross cap: u, v = var('u,v') fx = (1+cos(v))*cos(u) fy = (1+cos(v))*sin(u) fz = -tanh((2/3)*(u-pi))*sin(v) parametric_plot3d([fx, fy, fz], (u, 0, 2*pi), (v, 0, 2*pi), frame=False, color="red")
3D rendering not yet implemented
3D rendering not yet implemented
# EXERCISE: plot your favorite surface! # The graph of a function is a parametric plot: f_x=x, f_y=y, f_z=z(x,y) # ...