Why do I sometimes obtain complex solutions when I use the FSOLVE function or other Optimization Toolbox functions?

28 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The Optimization Toolbox functions, or any other minimization function, should not return any complex solutions. The most common cause of this is that the objective function called by the minimization function returns a complex value. This can occur in several situations, such as when you take the square root of a negative number and/or raise a negative number to a fractional power.
For example, in the following code, where x is a negative number, complex and imaginary solutions will be generated.
sqrt(x)
x^(1/2)
To avoid these problems, you need to bound your solution so that complex numbers are not generated, or you may need to adjust the output of your function to insure that it doesn't produce any complex outputs. To accomplish this bounding you must investigate what causes you objective function to return complex numbers. It maybe that there are mathematical properties of the function you were not aware of.
Another possible explanation is that bounds need to be set on the acceptable solutions. You can set bounds with most functions in the Optimization Toolbox. Consult the documentation for the function you are using where the bounding variables are usually called UB and LB.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!