ODE¶
- class pathsim.blocks.ode.ODE(func=<function ODE.<lambda>>, initial_value=0.0, jac=None)[source]¶
Bases:
BlockOrdinary differential equation (ODE) defined by its right hand side function.
\[\begin{split}\begin{align} \dot{x}(t) &= \mathrm{func}(x(t), u(t), t) \\ y(t) &= x(t) \end{align}\end{split}\]with inhomogenity (input) u and state vector x. The function can be nonlinear and the ODE can be of arbitrary order. The block utilizes the integration engine to solve the ODE by integrating the func, which is the right hand side function.
Example
For example a linear 1st order ODE:
ode = ODE(lambda x, u, t: -x)
Or something more complex like the Van der Pol system, where it makes sense to also specify the jacobian, which improves convergence for implicit solvers but is not needed in most cases:
import numpy as np #initial condition x0 = np.array([2, 0]) #van der Pol parameter mu = 1000 def func(x, u, t): return np.array([x[1], mu*(1 - x[0]**2)*x[1] - x[0]]) #analytical jacobian (optional) def jac(x, u, t): return np.array( [[0 , 1 ], [-mu*2*x[0]*x[1]-1, mu*(1 - x[0]**2)]] ) #finally the block vdp = ODE(func, x0, jac)
- Parameters:
func (callable) – right hand side function of ODE
initial_value (array[float]) – initial state / initial condition
jac (callable, None) – jacobian of ‘func’ or ‘None’
- op_dyn¶
internal dynamic operator for ODE right hand side ‘func’
- Type:
- update(t)[source]¶
update system equation for fixed point loop, here just setting the outputs
Note
the ODE block has no direct passthrough, so the ‘update’ method is optimized for this case
- Parameters:
t (float) – evaluation time