Azzera filtri
Azzera filtri

fsolve and complex solution?

4 visualizzazioni (ultimi 30 giorni)
John Miller
John Miller il 18 Giu 2012
Hello,
my test function is f=x^2+1 the slution is easy : x1=i orx2=-i (both are imaginary)
fsolve is not finding these values...why? fsolve returns 0 for a solution??
Thank you.
  4 Commenti
Walter Roberson
Walter Roberson il 18 Giu 2012
And you are not getting any warning message about it not being able to solve the problem?
I take it you overlooked this line in the documentation:
"fsolve only handles real variables. When x has complex variables, the variables must be split into real and imaginary parts."
John Miller
John Miller il 18 Giu 2012
fsolve returns the following message:
No solution found.
fsolve stopped because the problem appears regular as measured by the gradient,
but the vector of function values is not near zero as measured by the
default value of the function tolerance.
<stopping criteria details>
x =0
fval =1
I should split x in real and imaginary? Like this:
F = (r+i*s)^2+1; ?

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 18 Giu 2012
function F = myfun(ripair)
x = ripair(1) + ripair(2)*1i;
F = x^2+1;
if imag(F) ~= 0; F = 10^5; end %you need to emit finite real value from myfun
end
and make sure your x0 has a pair of values.

Più risposte (0)

Categorie

Scopri di più su Systems of Nonlinear Equations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by