@@ -160,8 +160,8 @@ function linearize!(
160160 linmodel:: LinModel{NT} , model:: SimModel ;
161161 x= (model. buffer. x.= model. x0.+ model. xop), u= model. uop, d= model. dop
162162) where NT<: Real
163- # using linmodel.buffer since default arguments already use model.buffer:
164- nonlinmodel, buffer = model, linmodel . buffer
163+ nonlinmodel = model
164+ buffer = nonlinmodel . buffer
165165 # --- compute the Jacobians at linearization points ---
166166 linearize_core! (linmodel, nonlinmodel, x, u, d) # no deviation vectors in model.linfunc!
167167 # --- remove the operating points of the nonlinear model (typically zeros) ---
@@ -172,16 +172,19 @@ function linearize!(
172172 # --- compute the nonlinear model output at operating points ---
173173 x0next, y0 = linmodel. buffer. x, linmodel. buffer. y
174174 h! (y0, nonlinmodel, x0, d0, model. p)
175- y = y0
176- y . = y0 .+ nonlinmodel . yop
175+ y0 .+ = nonlinmodel . yop
176+ y = y0
177177 # --- compute the nonlinear model next state at operating points ---
178178 f! (x0next, k0, nonlinmodel, x0, u0, d0, model. p)
179- xnext = x0next
180- xnext .= x0next .+ 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
181184 # --- modify the linear model operating points ---
182185 linmodel. uop .= u
183- linmodel. yop .= y
184186 linmodel. dop .= d
187+ linmodel. yop .= y
185188 linmodel. xop .= x
186189 linmodel. fop .= xnext
187190 # --- reset the state of the linear model ---
0 commit comments