I have a set of three coupled autonomous equations:
${y_{1}}\prime = y_{1}(\frac{\Omega_{m}}{y_{1}^3} + \frac{y_{3}^2}{6.0} + \frac{V(y_{2})}{2.H_{0}^2})$
$y_{2}\prime = y_{3}$
$y_{3}\prime = -3\frac{y_{1}\prime}{y_{1}}y_{3} - \frac{1}{H_{0}^2}\frac{\partial v(y2)}{\partial y_{2}}$
And I have used the following code to solve it using scipy.odeint:

def f(y,t):
    Xi = y[0]
    Yi = y[1]
    Zi = y[2]
    f0 = Xi*(onr/(Xi**3) + (H**2)*(Zi**2)/(2.0*rho_c) + (v0*np.exp(-l*Yi*k))/(rho_c))**(1.0/2.0)
    f1 =  Zi
    f2 =  -3*Zi*(H**2)*(onr/(Xi**3) + (H**2)*(Zi**2)/(2.0*rho_c) + (v0*np.exp(-l*Yi*k))/(rho_c))**0.5 + (l*k*v0*np.exp(-l*Yi*k))/(H**2)
    return [f0,f1,f2]

X0 = [1.0]
Y0 = [1.0]
Z0 = [c]
y0 = [X0,Y0,Z0]
t = np.linspace(start=1.0,stop=0.0,num=10001)

soln = odeint(f,y0,t)
X = soln[:,0]
Y = soln[:,1]
Z = soln[:,2]  

But when I run it ValueError: Initial condition y0 must be one-dimensional shows up. What should I do? I am new to python and this is the first time I am using this. Any help or explanation here would be great.

  • $\begingroup$ Debugging help at SciComp.SE, as with StackOverflow, requires a minimal, complete, and verifiable example. Code alone may not be enough for Readers to reproduce the error you report, and it would be worthwhile for you to try and get this error with fewer lines of code. $\endgroup$ – hardmath Jul 8 '17 at 1:36

You shouldn’t have defined X0, Y0, and Z0 as lists. As it stands, y0 is a list of lists – i.e., two-dimensional. You can solve this by replacing the respective lines with:

X0 = 1.0
Y0 = 1.0
Z0 = c
| cite | improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.