Finding all real roots of complex function with fsolve
Afficher commentaires plus anciens
Hi,
Is it possible to force fsolve to return only real roots of a complex function? I have this small code;
myfun = @det_sine_strip_Epol; % function
x = NaN*ones(22,1); % Initializes x.
for i=1:22
% Look for the zeros in the function's current window.
x(i)=fsolve(myfun,i);
end
x
which returns me this;
x =
0.8834 + 2.8654i
2.2244 + 3.0639i
2.9243 + 2.7614i
3.8319 + 0.0004i
5.1355 + 0.0003i
6.2468 + 2.7330i
7.0153 + 0.0000i
8.2545 + 2.8118i
8.7717 + 0.0003i
9.9364 + 0.0005i
11.0631 + 0.0017i
12.3366 + 2.6819i
13.0150 + 0.0000i
14.3013 + 2.5617i
14.9308 - 0.0000i
16.0375 + 0.0001i
17.0036 + 0.0000i
17.9597 + 0.0003i
18.9801 + 0.0001i
19.9942 + 0.0000i
21.0889 + 0.0038i
22.0467 + 0.0011i
where it actually should return ;

I am not specifically looking to calculate roots of the bessel, it is just one case.
Lastly, I see that fsolve missed couple of roots like (2.4048), and can find it only when i give initial guess as 2.4. Do you think it is supposed to be?
Thanks in advance.
Réponse acceptée
Plus de réponses (2)
Star Strider
le 15 Déc 2016
One way would be to define the initial estimates as:
r = linspace(0, 22, 100)
for i=1:length(r)
% Look for the zeros in the function's current window.
x(i)=fsolve(myfun,r(i));
end
xu = uniquetol(x, 1E-6);
xr = xu(imag(xu < 1E-6));
NOTE— This is UNTESTED CODE but should work. You may need to adjust the tolerances to give the result you want.
2 commentaires
ttopal
le 15 Déc 2016
Walter Roberson
le 15 Déc 2016
xr = real( x(abs(imag(x))<1E-6) );
xu = uniquetol(xr, 1E-6);
Walter Roberson
le 15 Déc 2016
1 vote
"Is it possible to force fsolve to return only real roots of a complex function?"
No. You need to use some other routine. For example if you have the symbolic toolbox then you could use vpasolve() with variables constrained to be real-valued (but even then, sometimes vpasolve will ignore constraints.)
"Finding all real roots of complex function"
It has been proven that there is no algorithm that can do that in the general case: there are functions for which it can be proven that knowledge of the function value at any finite number of other locations does not give you any information about the function value at any particular location. There are other functions for which that might not be the case but none-the-less the locations of the real zeros are beyond all current mathematics, with many people having put a lot of effort into some of the situations. For example, the Reimann Hypothesis about the Zeta function is a statement about complex zeros, but for some of the interesting properties the questions can be restated in terms of positive integers.
Catégories
En savoir plus sur Choose a Solver dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!