Plot a function of two variables

조회 수: 206 (최근 30일)
SA
SA 2021년 3월 13일
댓글: SA 2021년 3월 13일
I want to plot the function sin(4*pi*x)*sin(4*pi*y).
I tried the following but I am not sure if I am doing the right thing. Any help will be appreciated. Thanks
h = 2/11;
x = -1+h:h:1-h;
y = x;
[X,Y] = meshgrid(x,y);
z = @(x,y) sin(4*pi*x).* sin(4*pi*y); % Create Function
plot(x, z(X,Y))
  댓글 수: 2
Cris LaPierre
Cris LaPierre 2021년 3월 13일
편집: Cris LaPierre 2021년 3월 13일
What are you trying to do? Describe that, and then we can tell you if you are doing the right thing.
SA
SA 2021년 3월 13일
The function sin(4*pi*x)*sin(4*pi*y) is the exact solution to a Poisson equation and I want to plot the exact solution given the domain -1<=x<=1 and -1<=y<=1 and a dimension of 11 in both directions.

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

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 3월 13일
I think you want to plot a surface rather than a line plot. Use surf with inputs X, Y and z. This will allow you to see the response over the full X-Y parameter space. Since the number of points will affect the resolution of this surface, I use linspace instead of the colon operator.
h = 2/11;
x = linspace(-1+h,1-h,50);
y = x;
[X,Y] = meshgrid(x,y);
z = @(x,y) sin(4*pi*x).* sin(4*pi*y); % Create Function
surf(X,Y,z(X,Y))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by