JointEq#
- class brainpy.JointEq(*eqs)[source]#
Make a joint equation from multiple derivation functions.
For example, we have an Izhikevich neuron model,
>>> a, b = 0.02, 0.20 >>> dV = lambda V, t, u, Iext: 0.04 * V * V + 5 * V + 140 - u + Iext >>> du = lambda u, t, V: a * (b * V - u)
If we make numerical solver for each derivative function, they will be solved independently.
>>> import brainpy as bp >>> bp.odeint(dV, method='rk2', show_code=True) def brainpy_itg_of_ode0(V, t, u, Iext, dt=0.1): dV_k1 = f(V, t, u, Iext) k2_V_arg = V + dt * dV_k1 * 0.6666666666666666 k2_t_arg = t + dt * 0.6666666666666666 dV_k2 = f(k2_V_arg, k2_t_arg, u, Iext) V_new = V + dV_k1 * dt * 0.25 + dV_k2 * dt * 0.75 return V_new
As you see in the output code, “dV_k2” is evaluated by \(f(V_{k2}, u)\). If you want to solve the above coupled equation jointly, i.e., evalute “dV_k2” with \(f(V_{k2}, u_{k2})\), you can use
brainpy.JointEq
to emerge the above two derivative equations into a joint equation, so that they will be numerically solved together. Let’s see the difference:>>> eq = bp.JointEq(eqs=(dV, du)) >>> bp.odeint(eq, method='rk2', show_code=True) def brainpy_itg_of_ode0_joint_eq(V, u, t, Iext, dt=0.1): dV_k1, du_k1 = f(V, u, t, Iext) k2_V_arg = V + dt * dV_k1 * 0.6666666666666666 k2_u_arg = u + dt * du_k1 * 0.6666666666666666 k2_t_arg = t + dt * 0.6666666666666666 dV_k2, du_k2 = f(k2_V_arg, k2_u_arg, k2_t_arg, Iext) V_new = V + dV_k1 * dt * 0.25 + dV_k2 * dt * 0.75 u_new = u + du_k1 * dt * 0.25 + du_k2 * dt * 0.75 return V_new, u_new
brainpy.JointEq
supports make nestedJointEq
, which means the instance ofJointEq
can be an element to compose a newJointEq
.>>> dw = lambda w, t, V: a * (b * V - w) >>> eq2 = bp.JointEq(eqs=(eq, dw))
- Parameters:
*eqs – The elements of derivative function to compose.