I have the code structure below. I would like to get some numerical results here.
import numpy as np
import scipy
from scipy import integrate
alpha = .99
t = np.linspace(0, .85, 5)
s = np.empty_like(t)
f = np.power(t - s, -alpha)
Int = integrate.simpson(f, s)
Int
I got the warnings below. I understand that the first term in t
, that is t[0]
causes the errors, particularly first two warnings. But I do not know how I can avoid these warnings. I cannot change the alpha
,t
or f
.
<ipython-input-1-6b0d0757bfac>:8: RuntimeWarning: invalid value encountered in power
f = np.power(t-s, -alpha)
/usr/local/lib/python3.8/dist-packages/scipy/integrate/_quadrature.py:414: RuntimeWarning: invalid value encountered in true_divide
h0divh1 = h0 / h1
/usr/local/lib/python3.8/dist-packages/scipy/integrate/_quadrature.py:416: RuntimeWarning: invalid value encountered in true_divide
y[slice1] * (hsum * hsum / hprod) +
nan
I tried to take t = np.linspace(1e-8, .85, 5)
. It did not work.
EDIT: The t
is stable. I cannot change it. I need to derive s
from t
or find a new definition for s
. So, I have
t = np.linspace(0, .85, 5)
array([0. , 0.2125, 0.425 , 0.6375, 0.85 ])
Let us take the s
as an array of zeros (array of ones also does not work for s
)
s = np.zeros_like(t)
array([0., 0., 0., 0., 0.])
and add 1
to f
to avoid the warning of RuntimeWarning: divide by zero encountered in power
f = (t1+1-s)** -.99
array([1. , 0.82633295, 0.70424421, 0.61370619, 0.54387612])
After this when I used the simpson
, it gives nan
.
Int = integrate.simpson(f, s)
nan
Depending on the definition of s
, I am constantly encountering a warning or an error .
The question is: What could be the right definition of s
along with the t
defined above?