I have a rather complicated function H(x)
, and I'm trying to solve for the value of x
such that H(x) = constant
. I would like to do this with an interpolation object generated from a discrete interval and the corresponding output of H(interval), where other inputs are held constant. I denote the interpolation object f
.
My problem is that the call function of the interpolation object accepts an array_like, so passing a symbol to f(x)
to use sage's solver method is out of the question. Any ideas of how to get around this?
I have interpolation function f
. I would like to solve the equation f(x) == sageconstant for
x.
from scipy.interpolate import InterpolatedUnivariateSpline as IUspline
import numpy as np
#Generating my interpolation object
xint = srange(30,200,step=.1)
val = [H(i,1,.1,0,.2,.005,40) for i in srange(30,299,step=.1)]
f = IUspline(xint,val,k=4)
#This will yield a sage constant
eq_G(x) = freeB - x
#relation that I would like to solve
eq_m(x) = eq_G(39.9) == f(x)
m = solve(eq_m(x),x)
The above code (f(x)
to be more specific) generates
"TypeError: Cannot cast array data from dtype('0') to dtype('float64') according to the rule 'safe'.
edit: Any function H(x)
will result in the same error, hence it doesn't matter what H(x)
is. For simplicity (I wasn't kidding when I said H
is complicated), try H(x) = x
. Then the block will read:
from scipy.interpolate import InterpolatedUnivariateSpline as IUspline
import numpy as np
#Generating my interpolation object
xint = srange(30,200,step=.1)
H(x) = x
val = [H(i) for i in srange(30,299,step=.1)]
f = IUspline(xint,val,k=4)
#This will yield a sage constant
eq_G(x) = freeB - x
#relation that I would like to solve
eq_m(x) = eq_G(39.9) == f(x)
m = solve(eq_m(x),x)