-1

I am trying to define the following system of ODES in python: the following system of ODES in python

this way:

def rhs(t, P):
    dP = np.zeros_like(P)
    dP[0] = np.sqrt((1 - 3 / P) * (2 + 4 / P**2))
    dP[1] = 1 / math.pow(P,2)
    return dP

However, I am getting an error:

ValueError: setting an array element with a sequence.

I am not sure what is the problem... Would be grateful for any help with this!

Community
  • 1
  • 1
poisonedivy
  • 479
  • 4
  • 7
  • Does this answer your question? [ValueError: setting an array element with a sequence](https://stackoverflow.com/questions/4674473/valueerror-setting-an-array-element-with-a-sequence) – Ahmad Feb 27 '20 at 05:36

1 Answers1

0

Obviously, your state P has 2 components. Thus also the expressions you compute from P will have two components. Then you try to assign these tuples to a single cell in the array dP, which is not possible and results in that error message.

You might want to replace P with its first element P[0] in these expressions. Or use

def rhs(t, u):
    P,phi = u
    dP = ...
    dphi = ...
    return [dP, dphi]
Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51