Plotting wave equation

蹲街弑〆低调 提交于 2019-12-06 04:57:45

问题


I have been trying to plot a plane wave equation in Matlab. I am trying to plot the real part of, $(1/R)E^i(kR+wT)$ i.e. $(1/R)cos(kR+wT)$. So I used the following code in Matlab (for a single instant, say t=5),

x=-5:0.1:5;
y=-5:0.1:5;

t=5;

w=1.3;
k=1.3;

[X,Y]=meshgrid(x,y);
R=(X.^2+Y.^2)^1/2;
u=20*cos(k*R+w*t);
surf(X,Y,u);

When I run this code, I get the following surface plot:

This looks fine I think, as one would expect. But if I increase the wavenumber and angular frequency factors to 15, I get the following:

It appears to be an interference pattern but I have no idea why I am getting this because I did not put in the interference effects. Can anyone explain what is going on here?

What I am really trying to do is plot a function for radially outward moving spherical wave (on a surface, like surface of water may be) for demonstration in my class. How can I turn this into a animation which shows waves of waves moving out of a point source?

Thanks for your help


回答1:


You are seeing aliasing, which is caused by insufficient sampling. That aliasing has (at least) two possible causes:

  1. The sampling of the function defined by the x,y-grid of values is insufficient.
  2. Matlab plots the graph on a figure with a limited number of screen pixels. The graphical rendering involves some kind of downsampling, if the matrix that has to be represented is large compared with the number of figure pixels. In that downsampling process, aliasing may appear.

As for the first type of aliasing: when you increase the wavenumber, the wave varies faster in the x and y directions. So, in order to visualize the function properly you need to reduce the sampling period in the same proportion.

This is your original code, only with k=15 and w=15; and with surf replaced by imagesc for greater clarity (the figure is like yours but seen "from above"):

x=-5:0.1:5;
y=-5:0.1:5;
t=5;
w=15;
k=15;
[X,Y]=meshgrid(x,y);
R=(X.^2+Y.^2)^1/2;
u=20*cos(k*R+w*t);
imagesc(x,y,u);

The resulting figure exhibits aliasing artifacts:

Now, using finer sampling

x=-5:0.01:5; %// note: 0.01: finer grid
y=-5:0.01:5;
t=5;
w=15;
k=15;
[X,Y]=meshgrid(x,y);
R=(X.^2+Y.^2)^1/2;
u=20*cos(k*R+w*t);
imagesc(x,y,u);

reduces the first type of aliasing. However, some artifacts are still visible in the figure:

This is probably caused by the second type of aliasing referred to above. To confirm this, I ran the same code in Matlab R2014b, which does a better job at avoiding aliasing caused by graphic rendering (note also that the default colormap has been changed on this version of Matlab). You can see that, compared with the previous figure, the results are improved:

Bottom line: use finer sampling, and move to Matlab R2014b if possible.



来源:https://stackoverflow.com/questions/27633985/plotting-wave-equation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!