0% found this document useful (0 votes)
20 views3 pages

Numerical Analysis

The document describes a Python program that implements Lagrange interpolation to find the interpolated value of a function at a given point using data points. It provides sample input and output of the program running on a test case with 3 data points to demonstrate its efficiency.
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)
20 views3 pages

Numerical Analysis

The document describes a Python program that implements Lagrange interpolation to find the interpolated value of a function at a given point using data points. It provides sample input and output of the program running on a test case with 3 data points to demonstrate its efficiency.
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/ 3

NAME: YISHAWU OMOTAYO FEYISHAWU

MATRIC NO: 19/1895

COURSE: NUMERICAL ANALYSIS II

COURSE CODE: COSC 312

ASSIGNMENT

Write a computer program in python to implement the language interpolation polynomial

import NumPy as np

# Reading number of unknowns


n = int(input('Enter number of data points: '))

# Making NumPy array of n & n x n size and initializing


# to zero for storing x and y value along with differences of y
x = np.zeros((n))
y = np.zeros((n))

# Reading data points


print('Enter data for x and y: ')
for i in range(n):
x[i] = float(input('x[' + str(i) + ']='))
y[i] = float(input('y[' + str(i) + ']='))

# Reading interpolation point


interpolation_point = float(input('Enter interpolation point: '))

# Set interpolated value initially to zero


yp = 0

# Implementing Lagrange Interpolation


for i in range(n):

p=1

for j in range(n):
if i != j:
p = p * (interpolation_point - x[j]) / (x[i] - x[j])

yp = yp + p * y[i]

# Displaying output
print('Interpolated value at %.3f is %.3f.' % (interploation_point, yp))
1. Use a test case of 3 different pairs of values to prove the efficiency of your program

solution

Enter number of data points: 3

Enter data for x and y:

x[0]=2

y[0]=4

x[1]=6

y[1]=7

x[2]=3

y[2]=5

Enter interpolation point: 78

Interpolated value at 78.000 is -395.000.

Process finished with exit code 0

You might also like