@@ -157,9 +157,9 @@ julia> linearize!(linmodel, model, x=[20.0], u=[0.0]); linmodel.A
157
157
```
158
158
"""
159
159
function linearize! (
160
- linmodel:: LinModel{NT} , model:: SimModel ;
160
+ linmodel:: LinModel , model:: SimModel ;
161
161
x= (model. buffer. x.= model. x0.+ model. xop), u= model. uop, d= model. dop
162
- ) where NT <: Real
162
+ )
163
163
nonlinmodel = model
164
164
buffer = nonlinmodel. buffer
165
165
# --- remove the operating points of the nonlinear model (typically zeros) ---
@@ -172,16 +172,19 @@ function linearize!(
172
172
# --- compute the nonlinear model output at operating points ---
173
173
x0next, y0 = linmodel. buffer. x, linmodel. buffer. y
174
174
h! (y0, nonlinmodel, x0, d0, model. p)
175
- y = y0
176
- y . = y0 .+ nonlinmodel . yop
175
+ y0 .+ = nonlinmodel . yop
176
+ y = y0
177
177
# --- compute the nonlinear model next state at operating points ---
178
178
f! (x0next, k0, nonlinmodel, x0, u0, d0, model. p)
179
- xnext = x0next
180
- xnext .= x0next .+ nonlinmodel. fop .- nonlinmodel. xop
179
+ x0next .+ = nonlinmodel. fop
180
+ xnext = x0next # xnext = f(x0,u0,d0) + fop - xop + xop = f(x0,u0,d0) + fop
181
+ # --- recompute x since it was modified in buffer.x ---
182
+ x0 .+ = nonlinmodel. xop
183
+ x = x0
181
184
# --- modify the linear model operating points ---
182
185
linmodel. uop .= u
183
- linmodel. yop .= y
184
186
linmodel. dop .= d
187
+ linmodel. yop .= y
185
188
linmodel. xop .= x
186
189
linmodel. fop .= xnext
187
190
# --- reset the state of the linear model ---
@@ -190,14 +193,14 @@ function linearize!(
190
193
end
191
194
192
195
" Call `linfunc!` function to compute the Jacobians of `model` at the linearization point."
193
- function linearize_core! (linmodel:: LinModel , model:: SimModel , x0, u0, d0 )
194
- x0next, y0 = linmodel. buffer. x, linmodel. buffer. y
196
+ function linearize_core! (linmodel:: LinModel , model:: SimModel , x, u, d )
197
+ xnext, y = linmodel. buffer. x, linmodel. buffer. y
195
198
A, Bu, C, Bd, Dd = linmodel. A, linmodel. Bu, linmodel. C, linmodel. Bd, linmodel. Dd
196
- cst_x = Constant (x0 )
197
- cst_u = Constant (u0 )
198
- cst_d = Constant (d0 )
199
+ cst_x = Constant (x )
200
+ cst_u = Constant (u )
201
+ cst_d = Constant (d )
199
202
backend = model. jacobian
200
- model. linfunc! (x0next, y0 , A, Bu, C, Bd, Dd, backend, x0, u0, d0 , cst_x, cst_u, cst_d)
203
+ model. linfunc! (xnext, y , A, Bu, C, Bd, Dd, backend, x, u, d , cst_x, cst_u, cst_d)
201
204
return nothing
202
205
end
203
206
0 commit comments