How to get cost function value in MATLAB


I am using acados in Matlab. I wonder how to get the objective function value from ocp in Matlab. I tried to directly call “ocp.get_cost” to get the cost value. But I compared the value with the cost I computed by myself and they are totally different. Is the function “ocp.get_cost” exactly output the cost value or is there something I missed?

Thanks a lot in advance!

Yes, it should evaluate and output the cost function at the current iterate.
Note that the stage cost terms are weighted with the time step that is covored by the subsequent shooting interval.

Ah, maybe I compute the cost wrongly. I will check this. Thanks very much.