fsolve and complex solution?

4 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2012-6-18
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 2012-6-18
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; ?

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2012-6-18
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by