0

I am trying to solve a system of 12 equations in Matlab. Because I have constraints on the minimum and maximum values of the variables I use lsqnonlin rather than fsolve. However, I would like the optimizer to stop once the output (sum of squared deviations from the point where each equation holds) is sufficiently close to zero. Is there a way to specify such a stopping criterion?

The standard stopping criteria are about comparing the change in the output value compared to previous iteration but this is less relevant for me.

fes
  • 127
  • 4

1 Answers1

0

Use the fmincon function to solve the equations with bounded constraints.

Because you have not provided anything, follow the example provided by MATLAB:

fun = @(x)1+x(1)/(1+x(2)) - 3*x(1)*x(2) + x(2)*(1+x(1)); % objective function
lb = [0,0]; % lower bounds
ub = [1,2]; % upper bounds
x0 = (lb + ub)/2; % initial estimate
x = fmincon(fun,x0,[],[],[],[],lb,ub)

This specifies the range 0<x(1)<1 and 0<x(2)<2 for the variables.

The fmincon function also lets you change the default options. To specify the tolerance for the output, set it:

options = optimoptions('fmincon','Display','iter','FunctionTolerance',1e-10);

This sets fmincon options to have iterative display, and to have a FunctionTolerance of 1e-10. Call the fmincon function with these nonstandard options:

x = fmincon(fun,x0,[],[],[],[],lb,ub,[],options)
Thales
  • 1,181
  • 9
  • 10