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

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일

1 개 추천

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.
Sriram Tadavarty
Sriram Tadavarty 2020년 4월 27일
Glad that it helped.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

릴리스

R2019b

태그

질문:

2020년 4월 27일

댓글:

2020년 4월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by