绘制波动方程 [英] Plotting wave equation

查看:93
本文介绍了绘制波动方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在Matlab中绘制平面波方程.我正在尝试绘制$(1/R)E ^ i(kR + wT)$的实数部分,即$(1/R)cos(kR + wT)$.因此,我在Matlab中使用了以下代码(在一瞬间,例如t = 5),

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);

运行此代码时,得到以下曲面图: 我认为这看起来不错,正如人们所期望的那样.但是,如果我将波数和角频率因子增加到15,则会得到以下结果: 它似乎是一种干扰模式,但我不知道为什么要得到这个,因为我没有考虑干扰效应.谁能解释这是怎么回事?

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?

感谢您的帮助

推荐答案

您正在看到 别名 ,这是由于采样不足所致.该别名至少有两个可能的原因:

  1. x y -值网格定义的函数的采样不足.
  2. Matlab在具有有限数量的屏幕像素的图形上绘制图形.如果要表示的矩阵与图形像素的数量相比较大,则图形渲染涉及某种形式的下采样.在该降采样过程中,可能会出现混叠.
  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.

关于第一类混叠:当增加波数时,波在 x y 方向上变化更快.因此,为了正确显示功能,您需要以相同比例减少采样周期.

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.

这是您的原始代码,仅包含k=15w=15;并将surf替换为imagesc以便更加清晰(该图就像您的图,但从上方"看到):

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:

这可能是由上面提到的第二种别名引起的.为确认这一点,我在 Matlab R2014b中运行了相同的代码,该代码

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:

底线:使用更精细的采样,并尽可能移至Matlab R2014b .

这篇关于绘制波动方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆