Understanding fsolve() output when number of function evaluations is exceeded

5 次查看(过去 30 天)
Solving a nonlinear squared system of equations using fsolve(), in a simplified manner my code looks like this:
options = ('Display', 'iter', 'TolX', 1e-6, 'TolFun', 1e-6,...
'MaxFunEvals',1e7,'MaxIter',1e7);
x1 = fsolve(@(x) num_ss_Al(x), x0, options)
Now, when the maximum number of function evaluations is reached (or the number of iterations) the variable "x1" actually gets assigned a non-zero complex part vector, i.e.:
x1 =
1.0e+02 *
Columns 1 through 9
0.0214 + 0.0003i 0.0026 - 0.0000i 0.0100 + 0.0000i 0.1005 + 0.0000i 0.0004 - 0.0003i 0.0000 - 0.0001i -0.0002 - 0.0000i 0.0026 + 0.0000i 0.6752 - 0.0000i
Columns 10 through 18
0.6720 - 0.0000i 0.0097 + 0.0005i 0.0028 - 0.0002i 0.0086 + 0.0003i 0.0000 - 0.0000i 0.0025 - 0.0001i 0.0006 + 0.0000i 0.0026 - 0.0002i 0.0020 + 0.0001i
Columns 19 through 27
-0.0010 + 0.0001i 0.0051 - 0.0001i -0.0030 - 0.0001i 0.0001 - 0.0000i -0.0028 - 0.0001i -0.0045 - 0.0003i -0.0104 - 0.0003i -0.0048 + 0.0010i -0.0030 + 0.0002i
Columns 28 through 36
0.0017 + 0.0001i -0.0315 - 0.0038i 0.0100 - 0.0000i 0.0100 + 0.0000i 0.0100 + 0.0000i 0.0100 + 0.0000i 1.2980 - 0.0000i 0.0094 + 0.0000i 0.0096 + 0.0000i
Columns 37 through 45
0.0100 + 0.0000i 0.0100 + 0.0000i 0.0100 - 0.0000i 0.0107 - 0.0001i 0.0107 - 0.0001i 0.0185 - 0.0001i 0.0151 - 0.0000i 0.0273 - 0.0003i 0.0225 - 0.0001i
Columns 46 through 54
0.0191 - 0.0001i 0.0270 - 0.0004i 0.0081 + 0.0009i 0.0081 + 0.0009i -0.0002 + 0.0000i -0.0001 - 0.0000i 0.0094 + 0.0001i 0.0122 - 0.0013i 0.0106 - 0.0001i
Columns 55 through 63
0.0081 + 0.0009i 0.0003 - 0.0004i 0.0082 + 0.0001i 0.0089 - 0.0001i 0.0113 + 0.0006i 0.0005 - 0.0005i 0.0108 + 0.0006i 0.0096 + 0.0000i 0.0004 - 0.0003i
Columns 64 through 68
0.0001 - 0.0001i 0.0100 + 0.0000i 0.0135 + 0.0000i 0.0168 + 0.0000i 0.0136 - 0.0006i
What do those values correspond to given that the solver stopped prematurely? I thought first that they might be last iteration's evaluated values, but as far as I know and as stated in documentation the solution is a real vector or array, then for me it'd not be obvious why would numbers with non-zero imaginary part be evalutated. I'd appreciate some help in understanding this, thanks!

回答(1 个)

Zuber Khan
Zuber Khan 2024-5-8
Hi,
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 follow either of the two ways:
  1. Bound your solution so that complex numbers are not generated.
  2. Adjust the output of your function to ensure that it doesn't produce any complex outputs. To accomplish this bounding, you must investigate what causes your 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. For instance, "lsqnonlin" is one such method which allows to specify lower and upper bounds on the variables. You can refer to the following documentation link in order to know more about "lsqnonlin" solver:
I hope this will help.
Regards,
Zuber

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by