Untitled

 avatar
unknown
python
3 years ago
661 B
5
Indexable
from sympy import *
import sympy as sy
import numpy as np
import matplotlib.pyplot as plt
#Se definen los valores
x = symbols("x")
xi = np.array([1.3, 1.6, 1.9])
f = np.array([0.6200860, 0.4554022, 0.2818186])
DF = np.array([ -0.5220232, -0.5698959, -0.5811571])
n=len(xi)
#Se inicializa el codigo en 0
h=0
hp=0
ph=0
for j in range(0,n):
    L=1
    for i in range(0,n):
        if i != j:
            L*=((x-xi[i])/(xi[j]-xi[i]))
    derivp = sy.diff(L)
    h = ((1-2*(x-xi[j])*derivp.subs(x,xi[j]))*L**2)
    hp = ((x-xi[j])*L**2)
    ph = ph+h*f[j]+hp*DF[j]
print("P(x)=", simplify(ph))
print("P","(x=",1.5,")=",ph.subs(x,1.5),sep="")
Editor is loading...