Currently i'm stuck in finding the lagrange polynomial Li function's derivative. This is how i write the Li function :
def Li(x, xArr, n):
L = 1
resArr = []
for i in range(n):
for j in range(n):
if j == i:
continue
L = L * ((x - xArr[j])/ (xArr[i] - xArr[j]))
resArr.append(round(L,4))
L = 1
return resArr
And i want to calculate the derivatives of the array results from the function. For example, if we try to hardcode it, with a given xArr = [10.5, 12] it will look like :
L[0] = (x - xArr[1]) / (xArr[0] - xArr[1]) * (x- xArr[0]) / (xArr[1] - xArr[0])
L[0] = (x - 12)/(10.5 - 12) * (x - 10.5)/(12 - 10.5)
L[0] = (x^2 - 22.5x + 126) / -2.25
and then we'll find the derivative of L[0] with that function (x^2 - 22.5x + 126) / -2.25, in manual solving, we can insert the x later, but if we code it, i assume that the code must know the x value first, right?
so, for example i give the x value = 11.5, and it makes the results of L[0] = 0.3333
and now i want to calculate the derivative of L[0] and the result will be :
L'[0] = 2x - 22.5 / -2.25 for x = 11.5
L'[0] = 0.5
Is there any ways to do so? I've tried using torch.tensor, and using np.diff, but the results is not satisfying. Thank you.