I am to numerically calculate the value of cost, for a certain optimal quadratic regulator. Cost in quadratic regulator is J=J(t)= int((x^2+u^2).dt, 0...inf). I have the numerical values of x and u as data signals. I want to calculate the total cost. Am I allowed to use Matlab syntax: sum(x.^2+u.^2), to have a nonscaled evaluation of cost for a fixed-step solver. Is it correct to evaluate J as J= sum((x.^2+u.^2).dt), where dt is the fixed-step size. The model has been simulated by Matlab syntax ode45 or similar solvers. What happens to the calculation if I don't use a fixed-step solver? And how to calculate cost for a variable-step solver?.