Symbolic Weights. Error in ocp_create in setting dimensions

Hi,

I am trying to use adaptive weights and hence need to use some symbolic variables and parameters in creating the weight matrix. I created the W matrix as a casadi variable of size 3x3.

Unfortunately I am getting an error while running the script.

Error using ocp_create
ocp_create: error setting cost_W, wrong dimension, got 1 x 1, need 3 x 3

I have checked everything and the dimension of the W matrix is correctly 3x3 of type SX. If I use a simple constant W matrix of type double then there is no issue.

Could it be an error with the conditions checking within acados or I should recheck my code?

Best regards,
Smit

Hi @smit,

symbolic weighting matrices are not supported, they have to be numeric.
This is also stated in the problem formulation https://github.com/acados/acados/blob/master/docs/problem_formulation/problem_formulation_ocp_mex.pdf
I agree the error message could be better.

It is still possible to have different weights at each stage of the ocp.
The values of the ocp_model, are just to initialize the solver.
They can be updated like this in Matlab.

ocp.set('cost_W', weight_matrix, stage_index);

Cheers,
Jonathan

Hi @FreyJo,

Thank you for the reply.
Is there a possibility that such a capability of using symbolic weighting matrices will be added in future? Or it wont be possible at all due to some fundamental limitations?

When running simulations on the Matlab script, it would be possible to change weights at each stage using ocp.set , but how can this be implemented when on Simulink?

regards,
Smit

The idea is to have only the model functions code generated by CasADi.
These are symbolic. We will not add this capability, also as it introduces more overhead.

What about using the external cost module and use parameters to define the varying weights?

As for Simulink, feel free to edit this function to have more/other inputs.

Best,
Jonathan

Hi @FreyJo

If you mean using parameters for the weight matrix and then change the parameters as an when required, then I am afraid that wont be possible. Because the weight matrix wont be of type double anymore.

Please let me know if I miss understood you and in that case, could you please elaborate what you meant here?

regards,
Smit

Hi @smit,

No, I meant the external cost module, see the problem formulation pdf, cost_expr_ext_cost, which has no weight matrix, just a CasADi expression.
You can do something like:

W = diag( p )
cost_expr_ext_cost = x'* W * x;
model.p = p

Cheers,
Jonathan