0% found this document useful (0 votes)
3 views4 pages

Numerical Assignment 2

The document contains solutions to three questions involving Newton's Forward and Backward Interpolation methods. It includes the calculation of forward and backward difference tables, and estimates values at specified points using the respective interpolation formulas. The estimated results for the given values are provided for each question.

Uploaded by

70152071
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Numerical Assignment 2

The document contains solutions to three questions involving Newton's Forward and Backward Interpolation methods. It includes the calculation of forward and backward difference tables, and estimates values at specified points using the respective interpolation formulas. The estimated results for the given values are provided for each question.

Uploaded by

70152071
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment No.

2
Question No. 1:

Solution
x = [40, 50, 60, 70, 80, 90]
y = [184, 204, 226, 250, 276, 304]
#Calculate forward difference table
n = len(y)
forward_diff = [y.copy()]
# Calculate differences row by row
for i in range(1, n):
row = []
for j in range(n - i):
row.append(forward_diff[i-1][j+1] - forward_diff[i-1][j])
forward_diff.append(row)
# Display the forward differences table
for row in forward_diff:
print(row)
# Apply the Newton’s Forward Interpolation Formula
def newton_forward(x_values, y_values, value):
n = len(x_values)
h = x_values[1] - x_values[0]
u = (value - x_values[0]) / h
result = y_values[0]
product = 1
# Apply the formula
for i in range(1, n):
product *= (u - (i - 1))
result += (product * forward_diff[i][0]) / math.factorial(i)
return result
import math
value = 43
result = newton_forward(x, y, value)
print(f"Estimated value at x = {value} is {result:.3f}")

Output
Estimated value at x = 43 is 189.790

Question No.2:

Solution
x = [80,85,90,95,100]
y = [5026,5674,6362,7088,7854]
# Calculate backward difference table
n = len(y)
backward_diff = [y.copy()]
for i in range(1, n):
row = []
for j in range(n - i):
row.append(backward_diff[i-1][j+1] - backward_diff[i-1][j])
backward_diff.append(row)
# Display the backward differences table
for row in backward_diff:
print(row)
def newton_backward(x_values, y_values, value):
n = len(x_values)
h = x_values[1] - x_values[0]
u = (value - x_values[-1]) / h # Change for backward interpolation
result = y_values[-1] # Start from last y value
product = 1
for i in range(1, n):
product *= (u + (i - 1)) # Change for backward interpolation
fact = 1
for j in range(1, i + 1):
fact *= j
result += (product * backward_diff[i][-1]) / fact # Use last column values
return result
value = 105
result = newton_backward(x, y, value)
print(f"Estimated value at x = {value} is {result:.3f}")

Output
Estimated value at x = 105 is 8666.000

Question No.3:

Solution
x = [1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3]
y = [5.474, 6.050, 6.686, 7.389, 8.166, 9.025, 9.974]
# Calculate forward difference table
n = len(y)
forward_diff = [y.copy()]
for i in range(1, n):
row = []
for j in range(n - i):
row.append(forward_diff[i-1][j+1] - forward_diff[i-1][j])
forward_diff.append(row)
# Display the forward differences table
for row in forward_diff:
print(row)
def newton_forward(x_values, y_values, value):
n = len(x_values)
h = x_values[1] - x_values[0]
u = (value - x_values[0]) / h
result = y_values[0]
product = 1
for i in range(1, n):
product *= (u - (i - 1))
fact = 1
for j in range(1, i + 1):
fact *= j
result += (product * forward_diff[i][0]) / fact
return result
value = 1.85
result = newton_forward(x, y, value)
print(f"Estimated value at x = {value} is {result:.3f}")
# Calculate backward difference table
backward_diff = [y.copy()]
for i in range(1, n):
row = []
for j in range(n - i):
row.append(backward_diff[i-1][j+1] - backward_diff[i-1][j])
backward_diff.append(row)
# Display the backward differences table
for row in backward_diff:
print(row)
def newton_backward(x_values, y_values, value):
n = len(x_values)
h = x_values[1] - x_values[0]
u = (value - x_values[-1]) / h
result = y_values[-1]
product = 1
for i in range(1, n):
product *= (u + (i - 1))
fact = 1
for j in range(1, i + 1):
fact *= j
result += (product * backward_diff[i][-1]) / fact
return result
value = 2.4
result = newton_backward(x, y, value)
print(f"Estimated value at x = {value} is {result:.3f}")
Output
Estimated value at x = 1.85 is 6.360
Estimated value at x = 2.4 is 11.018

You might also like