I have a function that is y = ax + b
where a and b are constants. I want to find out the maximum value of y. We know that if a = 0
then y = b
, otherwise the maximum value of y is infinity. So I tried to use scipy.interpolate.interp1d to get the answer. Running the example 2 below will result in an error message.
from scipy import interpolate
import math
# example 1 (works): y = x + 0
func1 = interpolate.interp1d([1,2], [1,2], fill_value='extrapolate')
print(func1(math.inf)) # this will print inf as expected
# example 2 (doesn't work): y = 1
func2 = interpolate.interp1d([1,2], [1,1], fill_value='extrapolate')
print(func2(math.inf)) # I'm expecting 1, however it showed array(nan)
Error message:
RuntimeWarning: invalid value encountered in multiply
y_new = slope*(x_new - x_lo)[:, None] + y_lo
Edit:
Replacing math.inf with a very large number, like func2(9223372036854775807)
works too.