0

So I am using scipy.integrate's solve_ivp to solve a system of 4 first order coupled differential equations. Here is the piece of code:

def bigF (a, b):
    return [f1(a, b), f2(a, b), f3(a, b), f4(a, b)]
X, Y = solve_ivp(bigF, (0.1, 15),[0.999, 0.003, -0.033, 0.067])

bigF is a collection of four functions, arguments being a('x') and b('y-array'), it is like y_0 ' = f1, y_1 ' = f2 and so on. The second argument is a tuple of initial and final x, and the final argument is the initial values of the four y's.

I get the following error[full message]:

Traceback (most recent call last): File "F:/Semester 6/Dissertation/Coding Part/inbuilt.py", line 11, in X, Y = solve_ivp(bigF, (0.1, 15), [0.999, 0.003, -0.033, 0.067]) ValueError: too many values to unpack (expected 2)

I have no idea what this means, google does not help much.

Hridey
  • 1
  • 1
  • 2
    your function returning 4 values and you are reading it into only 2 variables. One option is just use `x=your_function` or `a,b,c,d=your_function` – Amit Nanaware Apr 16 '21 at 05:42
  • Please give the full error message and the place of the code that it points to. You are unpacking `b` somewhere but only give a pair of 2 variables on the left side. // Or it is already for the full call, `solve_ivp` returns one structure, you need to manually unpack its many fields. – Lutz Lehmann Apr 16 '21 at 05:57
  • @AmitNanaware Okay I got it. – Hridey Apr 16 '21 at 06:03
  • @LutzLehmann I solved by using Z = solve_ivp() – Hridey Apr 16 '21 at 06:04
  • See for instance https://stackoverflow.com/a/65929146/3088138 for more details on using solve_ivp close to matlab's ode45 – Lutz Lehmann Apr 16 '21 at 06:23
  • Alright, thanks everyone! – Hridey Apr 17 '21 at 06:33

0 Answers0