Numerical Analysis Using Sage by George A. Anastassiou & Razvan A. Mezei

Numerical Analysis Using Sage by George A. Anastassiou & Razvan A. Mezei

Author:George A. Anastassiou & Razvan A. Mezei
Language: eng
Format: epub
Publisher: Springer International Publishing, Cham


If you wish, you can modify the previous code as follows, so it will print the entire table of divided differences.

#the array of data points given

points = [(2,1),(4,2),(8,3), (16,4)]

#we compute n from the size of the array

n = len(points)-1

#computes the set of divided differences

def PrintDividedDifferencesTable():

#create an array n+1 by n+1

divDiff = [[0 for i in range(n+1)] for i in range(n+1)]

#first column will contain the y values

#this is column 0!

for row in [0,1,2,..,n]:

divDiff[row][0]=points[row][1]

#compute, recursively the div differences

#one column at a time

#in second column will have f[.]

#in third column will have f[.,.], etc

for column in [1,2,..,n]:

#for a column, compute the value in each row

for row in [0,1, 2, .., n-column]:

divDiff[row][column]=(divDiff[row+1][column-1]

-divDiff[row][column-1])/(points[row+

column][0]-points[row][0])

for row in [0,1, 2, .., n]:

print points[row][0],"\t|", [ divDiff[row][column] for

column in [0,1,2,..,n-row]]

#call the function

PrintDividedDifferencesTable()

This will output



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.