Finding all real roots of complex function with fsolve
20 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposta accettata
Matt J
il 15 Dic 2016
Modificato: Matt J
il 15 Dic 2016
Is it possible to force fsolve to return only real roots of a complex function?
Although the documentation doesn't say so explicitly (that I can see), I don't think it is legal to apply fsolve to functions that are not R^n-->R^m. In other words, using complex-valued x and f(x) as you are doing is not allowed. The optimization toolbox solvers use algorithms based on real-valued optimization theory only, I am pretty sure, and any success with complex-valued input is going to be just luck.
You could, of course, re-write your objective function f(x) in real-valued form by breaking it into its real and imaginary parts,
x(i)=fsolve(@(z) [real(myfun(z)), imag(myfun(z))] ,i);
This would always return a real-valued root, assuming that one exists and that your initial guess is sufficiently close to it. As Walter says, however, no numerical solver can find all roots, in general.
3 Commenti
Alan Weiss
il 15 Dic 2016
There is some relatively recent documentation about the use of complex numbers in Optimization Toolboxâ„¢ Solvers. In summary, if you have analytic objective functions, then indeed you can use fsolve to produce a root starting from a complex initial point.
Alan Weiss
MATLAB mathematical toolbox documentation
Matt J
il 15 Dic 2016
Modificato: Matt J
il 15 Dic 2016
In summary, if you have analytic objective functions, then indeed you can use fsolve to produce a root starting from a complex initial point.
Interesting. And this is an algorithm-independent, theoretical result? It doesn't matter, say, whether you use trust-region or Levenberg-Marquardt?
Più risposte (2)
Star Strider
il 15 Dic 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 Commenti
Walter Roberson
il 15 Dic 2016
xr = real( x(abs(imag(x))<1E-6) );
xu = uniquetol(xr, 1E-6);
Walter Roberson
il 15 Dic 2016
"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.
0 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!