This is easier than you think. :) Of course, that often is true, once you know the answer.
By the way, it can be a dangerous idea in general to use i as a variable name, since i is also sqrt(-1) by default in MATLAB. One day that will be important for you.
So what you have is a start:
x = 10:0.1:20;
n = 1;
J = besselj(n,x);
plot(x,J)
Now, do you know of some tool that can find a root, given a start point? Better yet, what if you have an interval in x that brackets a root? Note that fzero does exactly what you need, if you have an interval that brackets the root.
Is there a way you can locate pairs of points that bracket the root? What does that mean? Essentially, you need to find a pair of points x(m) and x(m+1), such that J(m) and J(m+1) have opposite signs. The sign function can help you here. For example:
m = find(diff(sign(J)) ~= 0)
m =
2 34 65 97
[J(m);J(m+1)]
ans =
0.018395515457572 -0.005177480554671 0.013894680686257 -0.002856572403405
-0.006615743297723 0.016599019864009 -0.005764213735631 0.015100612097755
So it appears there will be 4 roots in the interval of interest, because there are 4 zero crossings. Here is the first root:
fun = @(x) besselj(n,x);
[xvl,fval] = fzero(fun,[x(m(1)),x(m(1) + 1)])
xvl =
10.173468135062722
fval =
2.805130098197981e-16
Do the same call for each of the zero crossings identified in m.
3 Comments
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/502752-bessel-function-roots-and-zeros-on-interval-12-20#comment_791615
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/502752-bessel-function-roots-and-zeros-on-interval-12-20#comment_791615
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/502752-bessel-function-roots-and-zeros-on-interval-12-20#comment_791617
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/502752-bessel-function-roots-and-zeros-on-interval-12-20#comment_791617
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/502752-bessel-function-roots-and-zeros-on-interval-12-20#comment_792179
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/502752-bessel-function-roots-and-zeros-on-interval-12-20#comment_792179
Sign in to comment.