Clear Filters
Clear Filters

fsolve and complex solution?

4 views (last 30 days)
John Miller
John Miller on 18 Jun 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 Comments
Walter Roberson
Walter Roberson on 18 Jun 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 on 18 Jun 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; ?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 18 Jun 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.

More Answers (0)

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!