how to use fsolve with interval

Hi guys,
i got a problem with using fsolve, i want to define an interval for my problem but i can't.
This is my code
a = 20;
m = 12;
J = [0.01 0.02 0.05 0.1 0.2 0.5 1 2 5 10 20 50];
for j = 1:m
for i = 1:a
fnA=@(x) x*besselj(1,x)/besselj(0,x)-J(j);
A(i,j)=fsolve(fnA, i);
end
end
This code gives me roots of equation but it repeats roots sometimes. so i tried to replace this
A(i,j)=fsolve(fnA, i);
with
A(i,j)=fsolve(fnA, [start end]);
but i got error.
How can i solve it.
Thanks.

Respuestas (1)

Walter Roberson
Walter Roberson el 14 de Abr. de 2019

0 votos

fsolve() does not permit intervals to be specified.
fzero() permits specifying intervals. fzero() is restricted to single equations in one variable, which it appears might be good enough for your purpose.

5 comentarios

Sorry that i am a new on matlab, how do i overcome this problem. When i run this code,
a = 10;
m = 12;
J = [0.01 0.02 0.05 0.1 0.2 0.5 1 2 5 10 20 50];
for j = 1:m
for i = 1:a
fnA=@(x) x*besselj(1,x)/besselj(0,x)-J(j);
A(i,j)=fsolve(fnA, i);
end
end
i get this solution for first row of A
0,141244839250165
0,141247249128158
3,83431487980919
3,83431487971373
3,83431488000616
7,01701192336227
7,01701192164296
7,01701192161975
10,1744510362551
10,1744510362327
as you see some values are too close to each other. I couldn't remove them. Have you got an idea about this ?
Walter Roberson
Walter Roberson el 14 de Abr. de 2019
I am not sure what you expect. The roots are a varying distance apart, mostly slightly more than 3 apart. You are asking to solve at locations increasing by 1 each time. The "closest" root is going to stay the same for 2 to 3 numbers in a row (depending on exactly how the rounding works out.)
What is the task? Do you need to find a certain fixed number of roots? The "first" so-many roots? If so, then at any one point if the root you just found is within 1 of the previous root, then try the next integer. Once you have found two roots, then take the difference between them as and add that to the higher root to get the starting point for the next search.
It appears to me that as x increases, the distance between roots approaches pi.
ekrem yilmaz
ekrem yilmaz el 15 de Abr. de 2019
Hi Walter,
I m solving an eigenvalue problem, you can see my problem in picUntitled.png
Walter Roberson
Walter Roberson el 15 de Abr. de 2019
At the moment I do not see any connection between the A you solve for and the A you give the equation for.
Bi is given a subscript of i but not of n, which implies that as used in the equation for A that it should be independent of the n that is the variable of summation. But that seems weird. I suspect that B should be subscripted with n rather than i.
With Bi being Xn*J1/j0 and with it being used squared in A, that would be Xn^2*(J1/J0)^2 . But that is being used divided into Xn^2 in A, so that term would seem to calculate down to the simplier (J0/J1)^2.
I do not see any connection to eigenvalues.
ekrem yilmaz
ekrem yilmaz el 17 de Abr. de 2019
Hi Walter,
Sorry for late answer, i solved my problem about interval, thank you for answer mate
Have a nice day,

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 14 de Abr. de 2019

Comentada:

el 17 de Abr. de 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by