3

I am trying to use scipy's odeint to solve some ordinary differential equations. The only problem is that I only want to define one argument, and it seems that to make a tuple, you need at least two values.

My code looks like this:

def system(state, t, inputs)

    x = state[0]
    u = inputs
    a = -4
    b = 2

    dxdt = [a * x + b * u]

    return dxdt

inputs = 5
x_next = odeint(system, x, t, args=(inputs))

This will return an error because args must be a tuple, and (inputs) is a int/float and not a tuple. One way to overcome this is to put a, b as part of the args. But that is just a bandaid on a wound.

I was wondering if there is any ways to define the args as just one value.

Cleb
  • 25,102
  • 20
  • 116
  • 151
Rui Nian
  • 2,544
  • 18
  • 32

1 Answers1

4

As the error says args has to be a tuple. You can turn the current version easily into a tuple by using

args=(inputs,)

Note the additional comma.

Cleb
  • 25,102
  • 20
  • 116
  • 151