0% found this document useful (0 votes)
14 views1 page

Project

Mini Project 3rd year Mechanical

Uploaded by

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

Project

Mini Project 3rd year Mechanical

Uploaded by

salebharat5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

10/8/24, 12:19 PM Lagranges interpolation - Jupyter Notebook

Diksha Baride TE A1 T611005

In [1]: import numpy as np

In [2]: n = int(input('Enter number of data points: '))


x = np.zeros((n))
y = np.zeros((n))

Enter number of data points: 4

In [3]: for i in range(n):


x[i] = float(input("Enter x data point = "))
y[i] = float(input("Enter y data point = "))
Enter x data point = 0
Enter y data point = 2
Enter x data point = 1
Enter y data point = 3
Enter x data point = 2
Enter y data point = 12
Enter x data point = 5
Enter y data point = 147

In [4]: xp = float(input("Enter interpolation point: "))


yp = 0
Enter interpolation point: 3

In [5]: for i in range (n):

L = 1

for j in range (n):


if i != j:
L = L*(xp - x[j])/(x[i] - x[j])

yp = yp + L * y[i]

print('Interpolated value at xp = %f is yp = %f.' % (xp,yp))

Interpolated value at xp = 3.000000 is yp = 35.000000.

In [ ]: ​

localhost:8888/notebooks/TE A1 5/Lagranges interpolation.ipynb 1/1

You might also like