On the python implementation of the Lagrange and Neville interpolation algorithms

Source: Internet
Author: User

First step interpolation, the subject is very simple, the key is the algorithm part, I used the matrix data structure to store each iteration after the new value. The circle of the angle mark may be a little complicated at first, it will be clear when you go through it yourself.

1 #CODING=GBK2 " "3 Created on 2014-8-314 5 @author: Administrator6 " "7 8 defNeville (xt,m,n,x):9      forIinchRange (1, N):Ten          forJinchRange (1, N): OneW[i-j][i]= (X-xt[i-j])/(xt[i]-xt[i-J]) Am[i][j]=m[i-1][j-1]+w[i-j][i]* (m[i][j-1]-m[i-1][j-1]) -      forIinchrange (n): -          forJinchRange (0,i+1): the             ifj%n==0: -                 Print("\ n") -             Print('%f'%M[i][j]) -  +n = Int (input ('Number of INSERT nodes:')) -x = float (Input ('enter the value of x:')) +m = [[0 forIinchRange (n)] forJinchrange (n)] #创建n *n Matrix Aw = [[0 forIinchRange (n)] forJinchrange (n)] atXT = [0]*N -  forIinchrange (n): -M[i][0] = float (Input ('Insert%d y values:'% (i+1))) -  forIinchrange (n): -Xt[i] = float (Input ('Insert%d x value:'% (i+1))) -Neville (xt,m,n,x)

The following is a Lagrangian interpolation algorithm, very simple, sharing for reference.

1 #CODING=GBK2 " "3 Created on 2014-8-314 5 @author: Administrator6 " "7 defLagrange (X,XT,YT):8y =09      forIinchRange (3):Tent = 1 One          forJinchRange (3): A             ifi!=J: -t = t* (X-xt[j])/(xt[i]-Xt[j]) -y = y+t*Yt[i] the     Print("The result is:%f"%y) -  -XT = [] -YT = [] +x = float (Input ("interpolation x;")) -n = Int (input ("number of nodes;")) +  forIinchrange (n): AXt.append (Float (input ("the value of the first%d x"% (i+1)))) at  forIinchrange (n): -Yt.append (Float (input ("the value of the first%d x"% (i+1)))) -    -Lagrange (X,XT,YT)

On the python implementation of the Lagrange and Neville interpolation algorithms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.