from sympy import *
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
v=6500
x=Symbol("x")
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))
P=y0*L0+y1*L1+y2*L2+y3*L3+y4*L4
P_ec=expand(P)
s=P_ec.subs(x,v)
print("La gravedad para una altura de",v,"es",s)
print("El polinomio interpolador es",P_ec)
To embed this project on your website, copy the following code and paste it into your website's HTML: