Question regarding terminal cost in discrete time


I’m using the matlab interface.
I have a simple linear system in discrete time - no constraints.
I was just trying to reproduce the infinite horizon optimal control solution by using
[Kf,P] = dlqr(A,B,Q,R);
I used the same matrices Q,R,P in the acados formulation
expr_ext_cost_e = sym_x’ * P * sym_x;
expr_ext_cost = sym_x’ * Q * sym_x + sym_u’ * R * sym_u;

But the solution does not seem the same as -Kf*x(t)…
I played around a bit and found that adding a factor of the sampling time dT to the terminal cost gave the desired result:
expr_ext_cost_e = dT * sym_x’ * P * sym_x; % why dT here?
expr_ext_cost = sym_x’ * Q * sym_x + sym_u’ * R * sym_u;

I guess scaling the stage cost by 1/dT would give the same result. I also tried to solve the problem using Casadi and got the solution I expected.
Am I missing something or is this intended behavior?

Thanks for the help,

Hi Hannes,

a similar question has been asked here:

I agree that this is not documented prominently, I tried to address this here: