You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve LQR tutorial: add theoretical context, display optimal costs, fix matrix form note with backend option, correct API usage for objective and state
<details><summary>Click to unfold and see the matrix form.</summary>
68
+
```
69
+
70
+
The problem can also be written using matrix notation with the `backend=:default` option:
71
+
72
+
```@example main-lqr
73
+
x0 = [ 0
74
+
1 ]
75
+
A = [ 0 1
76
+
-1 0 ]
77
+
B = [ 0
78
+
1 ]
79
+
Q = [ 1 0
80
+
0 1 ]
81
+
R = 1
82
+
tf = 3
83
+
84
+
ocp = @def begin
85
+
t ∈ [0, tf], time
86
+
x ∈ R², state
87
+
u ∈ R, control
88
+
x(0) == x0
89
+
ẋ(t) == A * x(t) + B * u(t)
90
+
0.5∫( x(t)' * Q * x(t) + u(t)' * R * u(t) ) → min
91
+
end
92
+
93
+
solve(ocp; backend=:default, display=false)
94
+
```
95
+
96
+
!!! warning "Known issue"
97
+
98
+
Not using `backend=:default` with the ADNLPModels modeler (the default one) for the matrix form will lead to an error. This is a [known issue](@extref OptimalControl manual-abstract-known-issues).
We can observe that $x(t_f)$ converges to the origin as $t_f$ increases.
94
-
95
-
## Known issues
96
-
97
-
The following definition will lead to an error when solving the problem. This is a [known issue](@extref OptimalControl manual-abstract-known-issues).
98
-
99
-
```@repl main-lqr
100
-
101
-
x0 = [ 0
102
-
1 ]
103
-
104
-
A = [ 0 1
105
-
-1 0 ]
106
-
107
-
B = [ 0
108
-
1 ]
109
-
110
-
Q = [ 1 0
111
-
0 1 ]
112
-
113
-
R = 1
114
-
115
-
tf = 3
116
-
117
-
ocp = @def begin
118
-
t ∈ [0, tf], time
119
-
x ∈ R², state
120
-
u ∈ R, control
121
-
x(0) == x0
122
-
ẋ(t) == A * x(t) + B * u(t)
123
-
0.5∫( x(t)' * Q * x(t) + u(t)' * R * u(t) ) → min
124
-
end
125
-
126
-
solve(ocp)
127
-
```
144
+
We can observe that $x(t_f)$ converges to the origin as $t_f$ increases. This illustrates a fundamental property of the LQR problem: as the horizon extends, the optimal solution approaches the steady-state infinite-horizon LQR regulator, which drives the state to the origin with minimal cost.
0 commit comments