I'm trying to solve what is effectively a non-linear equation, containing a spline object. Since I want to do this many times with different data I don't want to create a new function for each data set, but create only one function and pass the spline on as an argument.
The data are in reality experimental data to which I fit a spline and the equation I'm trying to solve is rather complicated, but to illustrate my problem I'm using a simple sine function in the example below.
import numpy as np
from scipy import interpolate
from scipy.optimize import fsolve
import matplotlib.pyplot as plt
def equation(x0,func):
return ( interpolate.splev(x0,func) - 1 )
x = np.arange(0,2*np.pi,1)
y = np.sin(x)
yy = interpolate.splrep(x,y)
x0 = 3
root = fsolve(equation,x0,yy)
I get the following error:
TypeError: equation() takes exactly 2 arguments (4 given)
How can I do this? Any suggestion? Maybe it cant be done this way, and if so, is there another solution?