import numpy as np
import matplotlib.pyplot as plot
x0=0
x1=40000
x2=80000
x3=120000
x4=160000
y0=9.8100
y1=9.6878
y2=9.5682
y3=9.4511
y4=9.3364
n=10
X=np.linspace(0,160000,n+1)
L0=[]
L1=[]
L2=[]
L3=[]
L4=[]
P=[]
for i in range (0,n+1):
x=X[i]
L0.append(((x-x1)*(x-x2)*(x-x3)*(x-x4))/((x0-x1)*(x0-x2)*(x0-x3)*(x0-x4)))
L1.append(((x-x0)*(x-x2)*(x-x3)*(x-x4))/((x1-x0)*(x1-x2)*(x1-x3)*(x1-x4)))
L2.append(((x-x0)*(x-x1)*(x-x3)*(x-x4))/((x2-x0)*(x2-x1)*(x2-x3)*(x2-x4)))
L3.append(((x-x0)*(x-x1)*(x-x2)*(x-x4))/((x3-x0)*(x3-x1)*(x3-x2)*(x3-x4)))
L4.append(((x-x0)*(x-x1)*(x-x2)*(x-x3))/((x4-x0)*(x4-x1)*(x4-x2)*(x4-x3)))
P.append(y0*L0[i]+y1*L1[i]+y2*L2[i]+y3*L3[i]+y4*L4[i])
plot.plot(X,P)
plot.xlabel("x")
plot.ylabel("y")
plot.title("y vs x")
val=77000
x=val
L0_=((x-x1)*(x-x2)*(x-x3)*(x-x4))/((x0-x1)*(x0-x2)*(x0-x3)*(x0-x4))
L1_=((x-x0)*(x-x2)*(x-x3)*(x-x4))/((x1-x0)*(x1-x2)*(x1-x3)*(x1-x4))
L2_=((x-x0)*(x-x1)*(x-x3)*(x-x4))/((x2-x0)*(x2-x1)*(x2-x3)*(x2-x4))
L3_=((x-x0)*(x-x1)*(x-x2)*(x-x4))/((x3-x0)*(x3-x1)*(x3-x2)*(x3-x4))
L4_=((x-x0)*(x-x1)*(x-x2)*(x-x3))/((x4-x0)*(x4-x1)*(x4-x2)*(x4-x3))
res=(y0*L0_+y1*L1_+y2*L2_+y3*L3_+y4*L4_)
print("El resultado para el valor de",val,"es",res)
To embed this project on your website, copy the following code and paste it into your website's HTML: