How do you plot a Bessel function (2d) of the 1st kind in Matlab?
A:
Andreas Rejbrand
2010-04-30 23:35:49
+1
A:
Two parts to this:
- How to plot functions in MATLAB?
- How to evaluate a Bessel function over a given range?
duffymo
2010-04-30 23:37:43
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:
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:
Ramashalanka
2010-05-01 01:22:12
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
2010-05-01 11:48:36
@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
2010-05-01 21:26:49