In numerical analysis, Lagrange polynomials are used for polynomial interpolation. For a given set of distinct points Xi and numbers Yi, the Lagrange polynomial is the polynomial of the least degree that at each point Xj assumes the corresponding value Yj (i.e. the functions coincide at each point). The interpolating polynomial of the least degree is unique, however, and it is therefore more appropriate to speak of “the Lagrange form” of that unique polynomial rather than “the Lagrange interpolation polynomial”, since the same polynomial can be arrived at through multiple methods.
The Lagrange interpolating polynomial is the polynomial P(X) of degree <=(n – 1) that passes through the n points (x1, y1 = f(x1)),(x2, y2 = f(x2)) ,.., (xn, yn = f(xn)), , and is given by
(1)
|
where
(2)
|
Written explicitly,
(3)
|
The formula was first published by Waring (1779), rediscovered by Euler in 1783, and published by Lagrange in 1795 (Jeffreys and Jeffreys 1988).
Objective: To write a program in C to find the functional value of any value entered by user( using Lagrange’s Interpolation)
Algorithm for Lagrange’s Interpolation
- Scan for the number of data available. (data)
- Scan value for which f(x) – (datay[]) is to be calculated
- loop for i=0 to number_of_data
scan datax[i], scan datay[i], next i - loop for i to number_of_data
factor[i] = 1.0
loop for j to number_of_data
if i != j
factor[i] = factor[i] * (value – datax[j])/(datax[i]-datax[j])
end if, next j, next i - loop for i to number_of_data
sum = sum + factor[i] * datay[i]
next i - print the results
- Stop
C Program implementing Lagrange Interpolation Formula
#include 'studio.h' #include 'math.h' #define SIZE 40 int main(){ int i, j, data; float datax[SIZE], datay[SIZE], coeff[SIZE], value, sum=0.0, factor[SIZE]; printf("How many data are available? \n"); scanf("%d",&data); printf("\nEnter the value of x whose value is to be calculated?"); scanf("%f",&value); for(i=0; i<data ; i++){ printf("\nEnter X[%d]",i); scanf("%f",&datax[i]); printf("Enter Y[%d]",i); scanf("%f",&datay[i]); } for(i=0; i<data; i++){ factor[i] = 1.0; for(j=0; j<data; j++){ if(i!=j){ factor[i] = factor[i] * (value - datax[j])/(datax[i]-datax[j]); } } } printf("Coeff are: \n"); for(i=0;i<data;i++){ printf("\nfactor[%d] = %f",i, factor[i]); sum = sum + factor[i] * datay[i]; } printf("\n%f\n",sum); }
Formula source: Lagrange Interpolating Polynomial
play youtube
play youtube
xvideos
xporn
Phim sex
What Vaccines Do Dogs Need Annually
Wordle Jan 19
What Is Threshold Amount
My Pet Frame
Box Score For World Series
Louisville Women S Basketball Roster
Apple Savings Account Cons
Cso Criminal Search Bc
What Were Kleenex Tissues Originally Used For
Mens All Birds
Is Better Call Saul Over
Waitrose Warwick Way
Usd To Rm
How Much Is A Fitbit
Civil Liabilities Definition
What Is A Fast Internet Download Speedhulk Smash Birthday Cake
Waitrose Warwick Way
Rabies Vector Species
Gonzo Move
What Is The Sherman Act
Pingback: Bisection Method - Algorithm, Flowchart and Code in C - Code Snippets