Question

PLEASE USE PYTHON CODE The points x = -2, 1, 4, -1, 3, -4, y =...

PLEASE USE PYTHON CODE

The points

x = -2, 1, 4, -1, 3, -4,

y = -1, 2, 59, 4, 24, -53

lie on polynomial. Use the divided difference table of Newton's method to determine the degree of the polynomial.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# Newton divided difference formula  
  
# Function to find the product term  
def proterm(i, value, x):  
    pro = 1;  
    for j in range(i):  
        pro = pro * (value - x[j]);  
    return pro;  
  
# Function for calculating  
# divided difference table  
def dividedDiffTable(x, y, n): 
  
    for i in range(1, n):  
        for j in range(n - i):  
            y[j][i] = ((y[j][i - 1] - y[j + 1][i - 1]) /
                                     (x[j] - x[i + j])); 
    return y; 
  
# Function for applying Newton's  
# divided difference formula  
def applyFormula(value, x, y, n):  
  
    sum = y[0][0];  
  
    for i in range(1, n): 
        sum = sum + (proterm(i, value, x) * y[0][i]);  
      
    return sum;  
# The difference table  
def printDiffTable(y, n):  
  
    for i in range(n):  
        for j in range(n - i):  
            print(round(y[i][j], 4), "\t",  
                               end = " ");  
  
        print("");  
  
# The Driver Code 
  
# The number of inputs given  
n = 6;  
y = [[0 for i in range(10)]  
        for j in range(10)];  
x = [ -2,1,4,-1,3,-4];  
  
# y[][] is used for divided difference  
# table where y[][0] is used for input  
y[0][0] = -1;  
y[1][0] = 2;  
y[2][0] = 59;  
y[3][0] = 4;
y[4][0] = 24;
y[5][0] = -53;
  
# for calculating divided difference table  
y=dividedDiffTable(x, y, n);  
  
# for displaying divided difference table  
printDiffTable(y, n);  
  
# the value to be interpolated  
value = 7;  
# for printing the value  
print("\nValue at", value, "is", 
        round(applyFormula(value, x, y, n), 2)) 

Hope this helps you . Please give an upvote. Thank you.

Add a comment
Know the answer?
Add Answer to:
PLEASE USE PYTHON CODE The points x = -2, 1, 4, -1, 3, -4, y =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT