Plot f(x,y) = sin(2piX)sin(2piY)

17 次查看(过去 30 天)
William Baker
William Baker 2020-4-27
So I'm attempting to plot the function f(x,y) = sin(2*pi*X)*sin(2*pi*Y) on the interval [-2,2]x[-2,2], but I'm getting an odd looking graph. So far my code looks like this:
x = -2:.1:2
y = -2:.1:2
[X,Y] = meshgrid(x,y)
Z = sin(2*pi*X)*sin(2*pi*Y)
surf(X,Y,Z)
For some reason, it's only returning a Z value of 20. Any ideas?

回答(1 个)

Sriram Tadavarty
Sriram Tadavarty 2020-4-27
Hi William,
Try this:
x = -2:.1:2
y = -2:.1:2
[X,Y] = meshgrid(x,y)
Z = sin(2*pi*X).*sin(2*pi*Y) % Peform element wise multiplication
surf(X,Y,Z)
Hope this helps.
Regards,
Sriram
  2 个评论
William Baker
William Baker 2020-4-27
Wow, I could have sworn I tried this and it gave an error. Thanks so much, this fixed the issue.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by