Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download

Xudong Sun

Views: 22
Image: ubuntu2204
Kernel: Python 3 (system-wide)
Xudong Sun Graphing quadratic equation
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D a, b, c = 5, 3, 2 # Example values for a, b, c u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = a * np.outer(np.cos(u), np.sin(v)) y = b * np.outer(np.sin(u), np.sin(v)) z = c * np.outer(np.ones(np.size(u)), np.cos(v)) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_surface(x, y, z, color='b') plt.title('Ellipsoid') plt.show()
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # Constants for the dimensions of the hyperboloid a, b, c = 5, 3, 2 # You can change these values # Parametric variables u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(-5, 5, 100) u, v = np.meshgrid(u, v) # Parametric equations for the hyperboloid of one sheet x = a * np.cosh(v) * np.cos(u) y = b * np.cosh(v) * np.sin(u) z = c * np.sinh(v) # Plotting fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_surface(x, y, z, color='r', rstride=1, cstride=1) ax.set_title('Hyperboloid of One Sheet') plt.show()
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D a, b, c = 5, 3, 2 u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, 5, 100) u, v = np.meshgrid(u, v) x = a * np.sqrt(v**2 + 1) * np.cos(u) y = b * np.sqrt(v**2 + 1) * np.sin(u) z = c * v fig = plt.figure() ax1 = fig.add_subplot(121, projection='3d') ax1.plot_surface(x, y, z, color='g') ax2 = fig.add_subplot(122, projection='3d') ax2.plot_surface(x, y, -z, color='g') ax1.set_title('Hyperboloid of Two Sheets (Top)') ax2.set_title('Hyperboloid of Two Sheets (Bottom)') plt.show()
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D a, b = 5, 3 u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, 5, 100) u, v = np.meshgrid(u, v) x = a * v * np.cos(u) y = b * v * np.sin(u) z = v fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_surface(x, y, z, color='c') ax.set_title('Elliptic Cone') plt.show()
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D a, b = 5, 3 x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) x, y = np.meshgrid(x, y) z = (x**2 / a**2) - (y**2 / b**2) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_surface(x, y, z, color='y') ax.set_title('Hyperbolic') plt.show()
Image in a Jupyter notebook