python - Symbolically computing the input of an interpolation function? -
i have rather complicated function h(x), , i'm trying solve value of x such h(x) = constant. interpolation object generated discrete interval , corresponding output of h(interval), other inputs held constant. denote interpolation object f.
my problem call function of interpolation object accepts array_like, passing symbol f(x) use sage's solver method out of question. ideas of how around this?
i have interpolation function f. solve equation f(x) == sageconstant forx.
scipy.interpolate import interpolatedunivariatespline iuspline import numpy np #generating interpolation object xint = srange(30,200,step=.1) val = [h(i,1,.1,0,.2,.005,40) in srange(30,299,step=.1)] f = iuspline(xint,val,k=4) #this yield sage constant eq_g(x) = freeb - x #relation solve eq_m(x) = eq_g(39.9) == f(x) m = solve(eq_m(x),x) the above code (f(x) more specific) generates
"typeerror: cannot cast array data dtype('0') dtype('float64') according rule 'safe'.
edit: function h(x) result in same error, hence doesn't matter h(x) is. simplicity (i wasn't kidding when said h complicated), try h(x) = x. block read:
scipy.interpolate import interpolatedunivariatespline iuspline import numpy np #generating interpolation object xint = srange(30,200,step=.1) h(x) = x val = [h(i) in srange(30,299,step=.1)] f = iuspline(xint,val,k=4) #this yield sage constant eq_g(x) = freeb - x #relation solve eq_m(x) = eq_g(39.9) == f(x) m = solve(eq_m(x),x)
when working numpy , scipy, prefer python types sage types.
instead of sage integers , reals, use python ints , floats.
maybe can fix code this.
from scipy.interpolate import interpolatedunivariatespline iuspline import numpy np # generate interpolation object xint = srange(30,200,step=.1) xint = [float(x) x in xint] val = [float(h(i,1,.1,0,.2,.005,40)) in srange(30,299,step=.1)] f = iuspline(xint,val,k=4) # yield sage constant eq_g(x) = freeb - x # relation solve eq_m(x) = eq_g(39.9) == f(x) m = solve(eq_m(x),x)
Comments
Post a Comment