Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in python 2.7 that implements the n-point Lagrange interpolation

ID: 3890400 • Letter: W

Question

Write a program in python 2.7 that implements the n-point Lagrange interpolation. Treat n as an input
parameter.
Use your program to calculate values of following functions in n uniform points in the
[0.0,10.0] interval.
f (x) = exp(sin(ax))
Consider the values a = 12, 1, and 1.5. For a = 1, Comment on how the number of the base
points affects the quality of interpolation.
In a separate write-up, list in a table the result of evaluating the interpolating function for f(x)
for at least 5 values of x between 0 and 10. Do this for each of the above values of a.

**Please don't post the one code from github. that doesn't help* Don't forget the lagrange interpolation part! This is my third attempt asking this question

Explanation / Answer

from __future__ import print_function import random as rd import numpy as np value_n = int(input("Enter number of uniform points you want: ")) known_points = int(input("Enter number of know points you want: ")) points_to_find = np.linspace(1.0, 10.0, value_n) random_values = rd.sample(xrange(1,11), known_points) print(random_values) val_function_a_0 = [np.exp(np.sin(0.5 * val)) for val in random_values] print (val_function_a_0) val_function_a_1 = [np.exp(np.sin(1 * val)) for val in random_values] val_function_a_2 = [np.exp(np.sin(1.5 * val)) for val in random_values] list_functions = [val_function_a_0, val_function_a_1, val_function_a_2] def interpolate(given_val, val, known_points): result = 0 for i in range(known_points): term = given_val[i] for j in range(known_points): if j != i: term = term*((val - random_values[j])/(random_values[i] - random_values[j])) result = result + term return result for num in range(len(list_functions)): for val in points_to_find: inter = interpolate(list_functions[num],val, known_points) print ("For Function %d and value %f interpolate value is:" % (num, val), inter) print(" ")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote