# Nonlinear least squares MPC

Hello all,

I am a new user of the library, trying to solve an MPC problem for a multi-agent system through acados’ Matlab interface. My lagrange objective term is the sum of nonlinear terms like this: f_1(x(t))^2+f_2(x(t))^2+f_3(x(t))^2.

First of all, is there any example about the use of the ‘nonlinear_ls’ cost type? Also, any reference for when and how to prefer ‘cost_expr_y’?

I have tried to implement my problem by adding the nonlinear terms to the ‘cost_expr_y’ vector, with zero reference ‘cost_yr’. I am using ‘nonlinear_ls’ as cost type. The C code is generated successfully. However, the result is not as expected and in ‘ocp.model_struct.cost_expr_y’ I do not find the same function I assigned to ‘cost_expr_y’: sums and multiplications seem to be messed up and some ‘sq’ appear. Any clue of why this happens? Does ‘sq’ stands for ‘sqrt’?

Many thanks,
Enrica

Hi Enrica, thanks for your interest in acados! Could you share your example such that we can have a look?

Hi Enrica,

the nonlinear least squares objective is in the form `|| y(x,u) - y_ref ||^2_W`. The nonlinear term `y(x,u)` is the one which should get in the `cost_expr_y`. Both `y_ref` and `W` are treated as numerical, and should be represented by matlab matrices.

So in your case it would be `y(x,u) = [f_1; f_2; f_3]`, `y_ref=zeros(...)`, `W=eye(...)`.
If this is what you already did, you could send us a small self-contained code example which creates the expression for ‘cost_expr_y’ and the corresponding function you say it is not the one you assigned.

About constraints, there are three types: bounds `b` (comprising state bounds `bx` and input bounds `bu`), general affine `g` and nonlinear `h` constraints.
These suffixes are combined with the prefixes `n` for dimensions (e.g. `nbx`), `l`/`u` for upper and lower constraint vector (e.g. `lg`).
The prefix `J` (e.g. `Jbx`) represents a matrix made of rows from an identity matrix. This is a way to encode which of your states or inputs are bounded.

Cheers,

Gianluca

Sorry for the long silence.

I have solved two of the issues/questions I had and I’ll post here the answers. First, ‘sq’ in ‘ocp.model_struct’ stands for ‘square’ (^2) and not ‘sguare root’ (sqrt). Second, the expression in ‘ocp.model_struct.cost_expr_y’ is correct, only simplified. All zero terms are pruned in the compiling phase.

Also, the nonlinear least squares objective works as expected. Thank you, Gianluca, for the explanation.

Now, I am struggling to make the problem converge. Is there anywhere an explanation for what all the parameters mean and their possible values? Many of them, are common to Acado, so I have been looking to the Acado documentation here, but the list is not exhaustive and the values are sometimes different. Any help?

Cheers,
Enrica

Hi Enrica,

thanks for being so persistent.
I have been working on adding some comments on what the options mean to the examples and added checks to the Matlab interface.
In case of passing unsupported string options, it will also print the supported ones.