# Best way to implement and solve an ODE with a linearized RHS?

**URL:** <https://discourse.julialang.org/t/best-way-to-implement-and-solve-an-ode-with-a-linearized-rhs/117297>\
**Category:** Numerics\
**Tags:** question, diffeq, function, differentialequation, ordinarydiffeq\
**Created:** [July 21, 2024, 1:30pm UTC](https://discourse.julialang.org/t/best-way-to-implement-and-solve-an-ode-with-a-linearized-rhs/117297 "2024-07-21T13:30:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)\
**Post date:** [July 21, 2024, 1:30pm UTC](https://discourse.julialang.org/t/best-way-to-implement-and-solve-an-ode-with-a-linearized-rhs/117297/1 "2024-07-21T13:30:51Z")

</div>

Say, I have a system \dot{u} = f(u(t),t). I want to linearize the RHS at u(t\_{n}) and have \dot{u} = f(u(t\_n),t\_n) + f\_{u}'(u(t\_n),t\_n)\cdot(u(t)-u(t\_{n})).

In terms of DifferentialEquations.jl I can define `f(u,p,t)` where `u` corresponds to u(t). How can I pass `u_n` obtained at the previous step to `f(u,p,t)`?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 21, 2024, 3:11pm UTC](https://discourse.julialang.org/t/best-way-to-implement-and-solve-an-ode-with-a-linearized-rhs/117297/2 "2024-07-21T15:11:50Z")

</div>

That’s just a specific time stepper and not well-defined as a differential equation. I’m not 100% sure what you’re trying to ask.

---

<div class="post-metadata">

**Author:** ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)\
**Post date:** [July 21, 2024, 4:33pm UTC](https://discourse.julialang.org/t/best-way-to-implement-and-solve-an-ode-with-a-linearized-rhs/117297/3 "2024-07-21T16:33:22Z")

</div>

I want to do the following:

1. Fix timestep h, and `t_(n+1) = t_n + h`
2. Linearize the RHS at `u_n`
3. Solve linearized eq for `u_(n+1)`

The linearized RHS depends explicitly on `u_n`, which is basically a parameter which is obtained at the previous step. Using DiffEq interface, is it possible to update this parameter using a callback or anything else? In other words, take the result of the previous step and pass it to `f(u,p,t)` at the current step.
