Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate initial condition in ODE solver each time step
    primarykey
    data
    text
    <p>I am wanting to solve a system of ODEs where for the first 30,000 seconds, I want one of my state variables to start from the same initial value. After those 30,000 seconds, I want to change the initial value of that state variable to something different and simulate the system for the rest of time. Here is my code: </p> <pre><code>def ode_rhs(y, t): ydot[0] = -p[7]*y[0]*y[1] + p[8]*y[8] + p[9]*y[8] ydot[1] = -p[7]*y[0]*y[1] + p[8]*y[8] ydot[2] = -p[10]*y[2]*y[3] + p[11]*y[9] + p[12]*y[9] ydot[3] = -p[13]*y[3]*y[6] + p[14]*y[10] + p[15]*y[10] - p[10]*y[2]*y[3] + p[11]*y[9] + p[9]*y[8] - p[21]*y[3] ydot[4] = -p[19]*y[4]*y[5] - p[16]*y[4]*y[5] + p[17]*y[11] - p[23]*y[4] + y[7]*p[20] ydot[5] = -p[19]*y[4]*y[5] + p[15]*y[10] - p[16]*y[4]*y[5] + p[17]*y[11] + p[18]*y[11] + p[12]*y[9] - p[22]*y[5] ydot[6] = -p[13]*y[3]*y[6] + p[14]*y[10] - p[22]*y[6] - p[25]*y[6] - p[23]*y[6] ydot[7] = 0 ydot[8] = p[7]*y[0]*y[1] - p[8]*y[8] - p[9]*y[8] ydot[9] = p[10]*y[2]*y[3] - p[11]*y[9] - p[12]*y[9] - p[21]*y[9] ydot[10] = p[13]*y[3]*y[6] - p[14]*y[10] - p[15]*y[10] - p[22]*y[10] - p[21]*y[10] - p[23]*y[10] ydot[11] = p[19]*y[4]*y[5] + p[16]*y[4]*y[5] - p[17]*y[11] - p[18]*y[11] - p[22]*y[11] - p[23]*y[11] ydot[12] = p[22]*y[10] + p[22]*y[11] + p[22]*y[5] + p[22]*y[6] + p[21]*y[10] + p[21]*y[3] + p[21]*y[9] + p[24]*y[13] + p[25]*y[6] + p[23]*y[10] + p[23]*y[11] + p[23]*y[4] + p[23]*y[6] ydot[13] = p[15]*y[10] + p[18]*y[11] - p[24]*y[13] return ydot pysb.bng.generate_equations(model) alias_model_components() p = np.array([k.value for k in model.parameters]) ydot = np.zeros(len(model.odes)) y0 = np.zeros(len(model.odes)) y0[0:7] = p[0:7] t = np.linspace(0.0,1000000.0,100000) r = odeint(ode_rhs,y0,t) </code></pre> <p>So, in other words, I want to set y0[1] to the same value (100) each time <code>odeint</code> is called for the first 30,000 seconds. I'm effectively trying to let the system equilibrate for an amount of time before inputing a signal into the system. I thought about doing something like <code>if t &lt; 30000: y0[1] = 100</code> as the first line of my <code>ode_rhs()</code> function, but I'm not quite sure that works. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload