Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Polinomio de Lagrange - Python

# Hello World program in Python
    
from math import *

def LagrangePol (datos):
    def L(k, x): 
        out= 1.0
        for i,p in enumerate(datos):
            if i != k:
                out *= (x-p[0])/(datos[k][0]-p[0])
        return out
    
    def P(x): 
        lag = 0.0
        for k, p in enumerate(datos) :
            lag += p[1]*L(k, x)
        return lag
    
    return P
    
datosf =[(2.0,1.0/2.0), (11.0/4.0, 4.0/11.0), (4.0, 1.0/4.0)]
Pf = LagrangePol(datosf)
j =3.0
while j>0.0: 
    if j>0:
        print "\n"+r"-- Polinomio de Lagrange en x=:"+str(j)+"\n"
        print Pf(j)
        j=j-0.1
        

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.