0% found this document useful (0 votes)
6 views2 pages

Python MT

Uploaded by

muhammad komail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Python MT

Uploaded by

muhammad komail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import numpy as np def eq5_z(x, y):

import matplotlib.pyplot as plt return -y**2


from mpl_toolkits.mplot3d import Axes3D
def eq6_z(x, y):
def plot_3d_surface(x_range, y_range, z_func, return 1 - y**2
title):
""" def eq7_z(x, y):
Function to plot 3D surface for a given return x**2 + y**2
equation z = f(x, y)
def eq8_z(x, y):
:param x_range: Tuple containing (x_min, return x**2 + 2*y**2
x_max)
:param y_range: Tuple containing (y_min, # Plot the equations with their respective ranges
y_max) # 9x^2 + 4y^2 + 36z^2 = 36
:param z_func: A function that calculates z plot_3d_surface((-2, 2), (-2, 2), eq1_z, "9x^2 +
from x and y 4y^2 + 36z^2 = 36")
:param title: Title for the graph
""" # 9y^2 + z^2 = 16
x = np.linspace(x_range[0], x_range[1], 400) plot_3d_surface((-4/3, 4/3), (-4/3, 4/3), eq2_z,
y = np.linspace(y_range[0], y_range[1], 400) "9y^2 + z^2 = 16")
X, Y = np.meshgrid(x, y)
Z = z_func(X, Y) # 4y^2 + x + z^2 = 4
plot_3d_surface((-2, 2), (-2, 2), eq3_z, "4y^2 + x +
fig = plt.figure() z^2 = 4")
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z, cmap='viridis') # x^2 + y^2 - z^2 = 1
ax.set_title(title) plot_3d_surface((-2, 2), (-2, 2), eq4_z, "x^2 + y^2
ax.set_xlabel('x-axis') - z^2 = 1")
ax.set_ylabel('y-axis')
ax.set_zlabel('z-axis') # z + y^2 = 0
plt.show() plot_3d_surface((-2, 2), (-0.5, 2), eq5_z, "z + y^2
= 0")
# Define functions for each equation, using
np.maximum to avoid negative values inside the # z = 1 - y^2
square root plot_3d_surface((-2, 2), (-2, 2), eq6_z, "z = 1 -
def eq1_z(x, y): y^2")
return np.sqrt(np.maximum(0, (36 - 9*x**2 -
4*y**2) / 36)) # z = x^2 + y^2
plot_3d_surface((-3, 3), (-3, 3), eq7_z, "z = x^2 +
def eq2_z(x, y): y^2")
return np.sqrt(np.maximum(0, 16 - 9*y**2))
# z = x^2 + 2y^2 with different limits
def eq3_z(x, y): plot_3d_surface((-3, 3), (-3, 3), eq8_z, "z = x^2 +
return np.sqrt(np.maximum(0, 4 - 4*y**2 - x)) 2y^2, (-3 <= x <= 3, -3 <= y <= 3)")
plot_3d_surface((-1, 1), (-2, 3), eq8_z, "z = x^2 +
def eq4_z(x, y): 2y^2, (-1 <= x <= 1, -2 <= y <= 3)")
return np.sqrt(np.maximum(0, x**2 + y**2 - 1)) plot_3d_surface((-2, 2), (-2, 2), eq8_z, "z = x^2 +
2y^2, (-2 <= x <= 2, -2 <= y <= 2)")
plot_3d_surface((-2, 2), (-1, 1), eq8_z, "z = x^2 +
2y^2, (-2 <= x <= 2, -1 <= y <= 1)")

You might also like