Special functions in Matlab
I'm trying to get a picture like the following:
http://upload.wikimedia.org/wikipedia/en/e/e6/Airy-3d.svg
What am I doing wrong?
[x,y]=meshgrid(-1:.1:1,-1:.1:1);
surf(x,y,(2*besselj(1,2*pi*sqrt(x.^2+ y.^2)/sqrt(x.^2+ y.^2)).^2)
Also... kind of a side note, but if I used ndgrid instead of meshgrid here my x's and y's would switch ri开发者_StackOverflow社区ght?
Here are a couple of things I see wrong with the equation:
- There is a missing close parentheses somewhere in your equation, perhaps after the first
sqrt(x.^2+y.^2)
? In the equation, it appears that you are dividingsqrt(x.^2+y.^2)
by itself, which is probably not what you want to do and is why I was thinking you were missing a parentheses from around there. - You will probably want to perform element-wise division using
./
instead of matrix right division using/
(see this link for more detail).
In addition, you will want to change the 'FaceColor'
property of the surface object to 'none'
so that only the edges of the mesh are displayed:
[x,y] = meshgrid(-1:.1:1,-1:.1:1);
z = ... %# Compute your z in some way
surf(x,y,z,'FaceColor','none');
精彩评论