How to optimize the cost function with linear and nonlinear term

429 views
Skip to first unread message

Tran Huy

unread,
Oct 12, 2016, 7:52:35 AM10/12/16
to YALMIP
Dear John,
I meet a problem in solving a cost function including linear and nonlinear term in attach file. I have used toolbox IPOPT to solve however there are some error. I don't know solve this problem. Could you show my errors, please?
Best regards
Huy TRAN

Barrierfunction_MPC.m

Johan Löfberg

unread,
Oct 12, 2016, 8:09:58 AM10/12/16
to YALMIP
Define "some error"

Which version are you using? The current version does not support parameteris inside callback functions such as log etc. The previous version (september 2015) probably did

Tran Huy

unread,
Oct 12, 2016, 8:12:34 AM10/12/16
to YALMIP
Dear John,
the error like this:
Error using optimizer (line 297)
Parameters are currently only allowed to enter function such as exp, sin etc as exp(a), sin(b) etc.

Error in Barrierfunction_MPC (line 158)
controller = optimizer(constraints, objective,options,parameters,output);
BR

Tran Huy

unread,
Oct 12, 2016, 8:20:31 AM10/12/16
to YALMIP
I'm running Matlab 2015a

Johan Löfberg

unread,
Oct 12, 2016, 8:28:59 AM10/12/16
to YALMIP
Precisely, that's the limitation I talked about.

However, by simply trying to solve the problem without using optimizer framework, you see that ipopt doesn't like this problem

optimize([constraints, xsim(:,i) == x{1}, u_init == usim_init], objective,sdpsettings('debug',1,'solver','ipopt'))
EXIT: Invalid number in NLP function or derivative detected.

ans = 

  struct with fields:

    yalmiptime: 1.5279
    solvertime: 0.1931
          info: 'YALMIP called solver with incorrect input (IPOPT)'
       problem: 7




The reason is that ipopt will try to start from an initially infeasible point which happens to give inf in a logarithm.

I hope this whole code isn't some idea that you can avoid constrained optimization by relaxing constraints to logrirhmic barriers. That will only be more complicated than simply solving the constrained problem, as ipopt uses barriers internally anyway.

What you will have to do is that you have to initialize a feasible solution (either manually, or by solving an initial program which leads to a solution in the interior where the logarithms are defined), and then use that as an initial condition

It appears to be the nasty logarithmic stuff in the objective which is problematic. Solving the problem without objective to get an initial solution, and then solving with objective from there, at least gets IPOPT started. Unfortunately, the problem is not well-behaved, so ipopt is really slow on the second call
optimize([constraints, xsim(:,i) == x{1}, u_init == usim_init], [],sdpsettings('solver','ipopt'));;
optimize([constraints, xsim(:,i) == x{1}, u_init == usim_init], objective,sdpsettings('usex0','solver','ipopt'));;



Johan Löfberg

unread,
Oct 12, 2016, 8:29:54 AM10/12/16
to YALMIP
should be 'usex0',1,...

Johan Löfberg

unread,
Oct 12, 2016, 9:08:30 AM10/12/16
to YALMIP
BTW, I hope you realize a sum of squared logarithmic barriers is nonconvex

>> x = -1:0.01:1;
>> u = .5;
>> plot((-log(1-x)-log(x + 1)-log(2-u)-log(u+2)).^2)

so you have a rather nasty optimization problem

Tran Huy

unread,
Oct 12, 2016, 12:31:45 PM10/12/16
to YALMIP
Yes I know this problem sir. However its squared Gradient is still convex.

Johan Löfberg

unread,
Oct 12, 2016, 2:06:27 PM10/12/16
to YALMIP
Sure about that? Taking your code and simplifying to a model with -1<=x<=1 and -1<=u<=100000000 (yes, contrived, but just wanted to see a case in 2d)

x = (-.7:0.01:.7);
u = 0.5;
Bx=-log(-x+1)-log(1+x)-log(-u+100000000)-log(1+u);
Bx_0 = -8*log(10);
Bgr_x0 = 0;   
%Gradient recentered barrier function of state
Bgr_x = Bx - Bx_0 - Bgr_x0*x;
plot(x,Bgr_x.^2)    

Reply all
Reply to author
Forward
0 new messages