In: Advanced Math
I'm stuck on this python exercise using plots
Consider the hyperbolic paraboloid function:
z=x^2−y^2
Create several plots of the hyperbolic paraboloid function. Use true aspect ratio and label all axes.
Any help would be appreciated!Matlab can be used as long as the code can be used in Python as well
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator,
FormatStrFormatter
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
#making numbers starting from 0 to 5 (0 0.1 0.2 0.3
............4.9 5)
t1 = np.linspace(0, 5, 51)
t2 = np.linspace(0,2*math.pi,21)
[r,the]=np.meshgrid(t1,t2);
x1=np.multiply(r,np.cos(the));
y1=np.multiply(r,np.sin(the));
z1=np.square(x1)-np.square(y1);
# Plot the surface.
surf = ax.plot_surface(x1, y1, z1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_title('hyperbolic paraboloid')
ax.set_xlabel('x1')
ax.set_ylabel('y1')
ax.set_zlabel('z1')
# please see this
https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#mplot3d-tutorial
#you can use subplot also
#ax.legend()
# Customize the z axis.
#ax.set_zlim(-1.01, 1.01)
#ax.zaxis.set_major_locator(LinearLocator(10))
#ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
# Add a color bar which maps values to colors.
#fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()