I have written the following snippet of code:
import numpy as np
import math as m
import cmath as cm
from scipy.optimize import minimize, root_scalar
def omega(args,x):
N,p=args
w=new_target(N,p) #an array
old_spectrum=np.zeros(N)
for i in range(N-1):
old_spectrum[i]=N
old_spectrum[N-1]=0
sigma=0
for i in range(N):
sigma+=(w[i]*w[i])/(old_spectrum[i]-x)
return 1+sigma
def omega_prime(args,x):
N,p=args
w=new_target(N,p)
old_spectrum=np.zeros(N)
for i in range(N-1):
old_spectrum[i]=N
old_spectrum[N-1]=0
sigma=0
for i in range(N):
sigma+=(w[i]*w[i])/(old_spectrum[i]-x)*(old_spectrum[i]-x)
return sigma
def new_spectrum(N,p,x0):
roots=root_scalar(omega,fprime=omega_prime,args=(N,p),method='newton',x0=x0)
return rootsthat is meant to find the roots of a function omega(x) (there should be exactly N of them). However, calling for example new_spectrum(3,1,0.1)returns the error
Error:TypeError: omega() takes 2 positional arguments but 3 were given which I do not know how to fix. Any tips?

btw, do you have any idea how to extend the solver so that it doesn't stop once a root is found? Since I know there are N of them, ideally it would not stop until all N are found.