views:

205

answers:

3

How do you plot a Bessel function (2d) of the 1st kind in Matlab?

+1  A: 

Two parts to this:

  1. How to plot functions in MATLAB?
  2. How to evaluate a Bessel function over a given range?
duffymo
A: 

If you mean a 2d plot, you could choose a few \nu and overlay, using, e.g.

nu=0:0.5:3;
[nuGrid,z]=meshgrid(nu,linspace(0,10,100));
myBessel=besselj(nuGrid,z);
plot(z,myBessel)
xlabel('\nu')
ylabel('z')
zlabel('J_\nu(z)')
legend(cellstr(num2str(nu')))

which gives:

alt text

If you mean a plot of the function of two variables, here is a way (you can replace mesh with surf if you want) :

[nu,z]=meshgrid(linspace(0,5,100),linspace(0,10,100));
myBessel=besselj(nu,z);
mesh(nu,z,myBessel)
xlabel('\nu')
ylabel('z')
zlabel('J_\nu(z)')

Here is the resulting plot:

alt text

Ramashalanka
I am pretty sure he meant graphs of the type y = f(x) when he said "2D". I would call your first graph, of the form z = f(x, y), "3D".
Andreas Rejbrand
@Andreas: I thought that might be the case, and I saw it's what duffymo thought (by referring to `plot`). But I guessed the OP's "(2d)" wouldn't need stating and made me think (s)he meant it as a function of 2 variables. With 1 rep, well probably never see the OP again to know. Certainly the `surf` is a 3D plot of a function of 2 variables. I've changed the emphasis of my answer (and rejigged to avoid the for loop of the 2D plot).
Ramashalanka

related questions