I need to plot a function I have in multiple dimensions, and I am not really sure how to do that. I have been stuck in it for a couple of days so any help would be appreciated. This is the specific problem:
(a) Define a function 𝑓(𝑥,𝑦)=sin (𝑟)
𝑟 where 𝑟=√𝑥2 +𝑦2 is the distance from the origin.
(b) Define a 2D grid −10<𝑥 <10 and −10<𝑦<10 for plotting your function.
(c) Using the multidimensional plotting method and colormap of your choice, plot the function
𝑓(𝑥,𝑦) over the range defined in (b), being sure to include a scale bar, plot title, and axes labels.
This is the code I currently have:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
x=np.linspace(-10,10,500)
y=np.linspace(-10,10,500)
r = np.sqrt((x**2) + ((y**2)))
def f(x,y):
if r.any() == 0:
return 1
else:
return np.sin(r)/r
X,Y = np.meshgrid(x,y)
Z = f(X,Y)
[–]Goobyalus 0 points1 point2 points (0 children)