Advanced maths

Finite horizon linear quadratic control calculator with terminal cost

Solve a finite-horizon continuous-time linear quadratic regulator problem with a terminal quadratic cost.

Your numbers

Rows on separate lines; comma-separated values within each row.
Rows on separate lines; comma-separated values within each row.
Rows on separate lines; comma-separated values within each row.
Rows on separate lines; comma-separated values within each row.
Rows on separate lines; comma-separated values within each row.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Solve a finite-horizon continuous-time linear quadratic regulator problem with a terminal quadratic cost. The calculator integrates the Riccati equation backward, then the controlled state forward, reporting the initial value, feedback trajectory and a cost-identity diagnostic. Matrices are small and numerically bounded. This is an unconstrained deterministic control model with full state feedback, not an infinite-horizon algebraic Riccati solution.

THE FORMULA−P′=AᵀP+PA−PBR⁻¹BᵀP+Q, P(T)=F; u=−R⁻¹BᵀPx.

A worked example

For x′=u, control cost u², terminal cost x(1)² and x(0)=1, P(t)=1/(2−t), optimal x(t)=(2−t)/2 and u=−1/2. The initial value is 1/2, equal to control cost 1/4 plus terminal cost 1/4.

Good to know

≤3 states and 2 controls, constant matrices, positive definite R and semidefinite Q/F. RK4 backward Riccati plus forward trajectory, step refinement and cost-identity diagnostics. Reject unstable discretizations; no control bounds, stochastic model or nonlinear global-optimum claim.

State, control and cost conventions

The dynamics are state derivative equals A times state plus B times control. Running cost is state transpose Q state plus control transpose R control, with no extra one-half factor.

The terminal cost uses the supplied terminal matrix at the chosen horizon. Q and the terminal matrix must be symmetric positive semidefinite; R must be symmetric positive definite. Those conditions make the control penalty meaningful and permit the required inverse.

Finite-horizon feedback splits cost between control and terminal statex(t) = (2−t)/2u = −1/2Running cost: 1/4Terminal cost: 1/4
For x′=u, control cost u², terminal cost x(1)² and x(0)=1, P(t)=1/(2−t), optimal x(t)=(2−t)/2 and u=−1/2. The initial value is 1/2, equal to control cost 1/4 plus terminal cost 1/4. Static schematic; numerical labels define the example.

Returns a time-varying finite-horizon gain and trajectory; the existing algebraic discrete equation solves a stationary infinite-horizon problem. The Volterra integral equation calculator with a variable upper limit offers a complementary calculation under its own stated assumptions.

Why the Riccati equation runs backward

The terminal cost supplies the final condition for the matrix P. Backward integration propagates the future value of each state to earlier times.

The resulting optimal feedback is minus R inverse B transpose P times state. Because the remaining horizon changes, P and the feedback gain generally vary with time. Replacing them by the initial gain throughout the interval would solve a different control policy than the one represented by the finite-horizon calculation.

Worked example and mathematical rule

For x′=u, control cost u², terminal cost x(1)² and x(0)=1, P(t)=1/(2−t), optimal x(t)=(2−t)/2 and u=−1/2. The initial value is 1/2, equal to control cost 1/4 plus terminal cost 1/4.

−P′=AᵀP+PA−PBR⁻¹BᵀP+Q, P(T)=F; u=−R⁻¹BᵀPx.

The value function and factor conventions

The minimum cost from the initial state is its quadratic form with the initial Riccati matrix. Some texts put one-half factors in their objective or value function; gains and reported values must be compared under matching conventions.

The tool also integrates the running cost along the computed closed-loop trajectory and adds terminal cost. Agreement with the Riccati value is a useful independent numerical identity, not an excuse to omit the cost definition from a reported result.

Numerical trajectory construction

The backward Riccati and forward state equations use fourth-order Runge–Kutta integration. Feedback between stored Riccati nodes uses interpolation, introducing another approximation.

A finer run compares initial value estimates, while the quadrature-versus-value residual tests consistency of the forward trajectory and backward solution. A stiff or poorly scaled system can require a more suitable solver. Positive-definiteness checks and finite outputs do not by themselves establish numerical accuracy for arbitrary matrices.

Finite horizon does not imply asymptotic stability

A policy optimal over a limited interval with a terminal cost is not automatically a stabilizing infinite-time controller. A zero terminal cost can weaken control near the end because no future cost remains after the horizon.

Controllability and detectability questions matter in related settings, but this page does not present a complete systems certification. Inspect the modeled trajectory and horizon rather than treating the word optimal as a guarantee about every possible operating condition.

Real constraints require another formulation

Control saturation, state limits, disturbances, observation noise and actuator delays are absent. Clipping the returned control afterward generally destroys the stated optimality and changes the trajectory.

If those features matter, use constrained optimization or model predictive control with an appropriate plant model. The calculator is useful for checking small educational Riccati examples and cost conventions. Record every matrix, initial state, horizon and numerical diagnostic when comparing solutions or transferring a gain into a separate simulation.

A few questions, answered

Is there a one-half factor in the objective?

No. The displayed convention uses the full quadratic forms.

Is the gain constant?

Generally not. Finite-horizon Riccati feedback varies with time.

Does this enforce actuator limits?

No. Control and state constraints are outside the model.

Does optimal mean stable forever?

No. The result optimizes the stated finite-horizon objective only.

Find your calculator

Start typing to explore the library.