Leezus
Leezus

Reputation: 19

Python TypeError: derivatives_circ() takes 2 positional arguments but 6 were given

i am trying to calculate some derivatives in order to complete some equations. but when i define my function which i would like to hold 6 different variables. it gives me this error bellow.

  File "C:\Users\Leona\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Leona/.matplotlib/Python_Dyn_Opdracht6_tweede.py", line 94, in <module>
    afgeleiden = derivatives_circ([theta[n], omega[n]], x[n], vx[n], y[n], vy[n], t[n])

TypeError: derivatives_circ() takes 2 positional arguments but 6 were given

this is the code i used to create the function

def derivatives_circ(state, t):             
    theta = state[0]                       
    omega = state[1]                        
    Moment=F*D
    alpha = Moment/Ig  
    
    x = state[2]
    vx = state[3]
    ax = F*np.cos(theta)/m 
    
    y = state[4]
    vy = state[5]
    ay = F*np.sin(theta)/m
    return [omega, alpha, vx, vy, ax, ay]



resultaat = odeint(derivatives_circ,[theta0, omega0, x0, vx0, y0, vy0], t)
theta = resultaat[:,0]
omega = resultaat[:,1]

x = resultaat[:,2]
vx = resultaat[:,3]

y = resultaat[:,4]
vy = resultaat[:,5]


for n in range(len(t)-1):
    if theta[n]<0.5*np.pi:
        
        afgeleiden = derivatives_circ([theta[n], omega[n]], x[n], vx[n], y[n], vy[n], t[n])
        omega[n+1] = omega[n] + afgeleiden[1]*dt 
        theta[n+1] = theta[n] + afgeleiden[0]*dt
        
        vx[n+1]=vx[n]+afgeleiden[3]*dt
        x[n+1]=x[n]+afgeleiden[2]*dt
        
        vy[n+1]=vy[n]+afgeleiden[5]*dt
        y[n+1]=y[n]+afgeleiden[4]*dt
    
    else:
        
        afgeleiden_circ = derivatives_circ([theta[n], omega[n]], x[n], vx[n], y[n], vy[n], t[n])
        omega[n+1] = omega[n] + afgeleiden_circ[1]*dt 
        theta[n+1] = theta[n] + afgeleiden_circ[0]*dt
        
        afgeleiden_lin = derivatives_circ([x[n],vx[n]],t[n])
        vx[n+1]=vx[n]+afgeleiden[3]*dt
        x[n+1]=x[n]+afgeleiden[2]*dt
        
        afgeleiden = derivatives_circ([y[n],vy[n]],t[n])
        vy[n+1]=vy[n]+afgeleiden_circ[5]*dt
        y[n+1]=y[n]+afgeleiden[4]*dt

Any help would really be appreciated!

Upvotes: 1

Views: 1581

Answers (2)

Amir Shabani
Amir Shabani

Reputation: 4217

In this line:

def derivatives_circ(state, t):

You defined this function so that it takes 2 arguments, but then in this line:

afgeleiden = derivatives_circ([theta[n], omega[n]], x[n], vx[n], y[n], vy[n], t[n])

You are giving it 6 arguments! That's why it's giving you the error. I don't know the mentality behind your code, but replacing it with this line:

afgeleiden = derivatives_circ([theta[n], omega[n], x[n], vx[n], y[n], vy[n]], t[n])

Should work!

Upvotes: 0

Hoog
Hoog

Reputation: 2298

This line here:

afgeleiden = derivatives_circ([theta[n], omega[n]], x[n], vx[n], y[n], vy[n], t[n])

should maybe be:

afgeleiden = derivatives_circ([theta[n], omega[n], x[n], vx[n], y[n], vy[n]], t[n])

based on your earlier calls to derivatives_circ

Upvotes: 2

Related Questions