Date post: | 02-Mar-2016 |
Category: |
Documents |
Upload: | rose-lynn-anne-besa |
View: | 4 times |
Download: | 0 times |
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 1/23
1
INTERPOLATING POLYNOMIALS
Polynomial interpolation is one of the most problems in numericalmethods. It is the interpolation of a given data set by a polynomial: givensome points, find a polynomial which goes exactly through these points.
Polynomials can be used to approximate more complicated curves, forexample, the shapes of letters in typography, given a few points. Arelevant application is the evaluation of the natural logarithm andtrigonometric functions: pick a few known data points, create a lookuptable, and interpolate between those data points. This results insignificantly faster computations. Polynomial interpolation also forms thebasis for algorithms in numerical quadrature and numerical ordinarydifferential equations.
A.
EQUALLY DIVIDED
1.
NEWTON’S FORWARD
Newton's forward difference formula is a finite difference identity giving
an interpolated value between tabulated points in terms of the firstvalue and the powers of the forward difference . For , theformula states
(1)
When written in the form
(2)
with the falling factorial, the formula looks suspiciously like a finiteanalog of a Taylor series expansion. This correspondence was one of themotivating forces for the development of umbral calculus.
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 2/23
2
PROGRAM GUIDE
1. Double click on the NEWTON’S FORWARD.exe to launch the
program.
2. In the program window, input the number of x desired then press
Enter. (see Figure 1-1)
Figure 1-1
3. Key in the values for xn and f(x)n pressing tab to separate xn and
f(x)n, such that xn<space>f(x)n. (see Figure 1-2)
Figure 1-2
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 3/23
3
4.
Type in the value for x in order to solve for P(x). (see Figure 1-3)
Figure 1-3
5. Press Enter. The resulting value for P(x) will be shown on the program
window. (see Figure 1-4)
Figure 1-4
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 4/23
4
SOURCE CODE
#include<stdio.h>#include<conio.h>#include<iostream.h>
#define max 100#define order 4main(){floatax[max+1],ay[max+1],diff[max+1][order+1],nr=1.0,dr=1.0,x,p,h,yp,y1,y2,y3,y4;int n,i,j,k;system("cls");printf("Enter the value of n:");scanf("%d",&n);
printf("\nEnter the values:\nx\ty\n");for(i=0;i<=n;i++)scanf("%f%f",&ax[i],&ay[i]);printf("\nEnter the value of x for which youwant the value of y:");scanf("%f",&x);h=ax[1]-ax[0];for(i=0;i<=n-1;i++)diff[i][1]=ay[i+1]-ay[i];for(j=2;j<=order;j++)for(i=0;i<=n-j;i++)
diff[i][j]=diff[i+1][j-1]-diff[i][j-1];p=(x-ax[0])/h;y1=p*diff[0][1];y2=p*(p-1)*diff[0][2]/2;y3=p*(p-1)*(p-2)*diff[0][3]/6;y4=p*(p-1)*(p-2)*(p-3)*diff[0][4]/24;yp=ay[0]+y1+y2+y3+y4;printf("\nFor x = %6.4f , P(x) = %6.4f\n",x,yp);getch();}
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 5/23
5
2.
NEWTON’S BACKWARD
This is another way of approximating a function with an nth degreepolynomial passing through(n+1) equally spaced points.
As a particular case, lets again consider the linear approximation to f(x)
f1 - f0 f0x1 - f1x0
f(x) = P1(x)=X+
x1 - x0 x1 - x0
x1 - x x - x0 f0 + f1
x1 - x0 x1 - x0
x - x1 (
x - x0 )= f1 - f0 + -1 f1
x0 - x1 x - x0
x - x1
= f1 - (f1- f0)
x1 - x0
where is the backward difference.
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 6/23
6
PROGRAM GUIDE
1. Double click on the NEWTON’S BACKWARD.exe to launch the
program.
2.
In the program window, input the number of x desired then press
Enter. (see Figure 2-1)
Figure 2-1
3.
Key in the values for xn while pressing Enter after each digit. (see
Figure 2-2) Figure 2-2
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 7/23
7
4.
Put in the values for and f(x)n while pressing Enter after each digit.
(see Figure 2-3)
Figure 2-3
5. Type in the value for x in order to solve for P(x). (see Figure 2-4)
Figure 2-4
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 8/23
8
6.
Press Enter. The resulting value for P(x) will be shown on the program
window. (see Figure 2-5)
Figure 2-5
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 9/23
9
SOURCE CODE
#include<iostream.h>#include<stdio.h>#include<conio.h>
#include<math.h>int main(){int i,j,n;float x[20],y[20],t,xv,yv;system("cls");printf("Enter number of x: ");scanf("%d",&n);for(i=0;i<n;i++){printf("\n\nEnter value for x%d f(x%d) : ",i,i);
scanf("%f%f",&x[i],&y[i]);}printf("\n\nEnter value for x for finding P(x):");scanf("%f",&xv);for(i=0;i<n;i++){t=y[i];
for(j=0;j<n;j++){
if(i!=j)
{ t=t*((xv-x[j])/(x[i]-x[j]));}
}yv=yv+t;}printf("\nP(x) = %f",yv,xv);getch();return 0;}
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 10/23
10
B.
UNEQUALLY DIVIDED
1.
LAGRANGE METHOD
Lagrange interpolation is a well known, classical technique forinterpolation. It is also called Waring-Lagrange interpolation, since Waringactually published it 16 years before Lagrange [311, p. 323]. Moregenerically, the term polynomial interpolation normally refers to Lagrangeinterpolation. In the first-order case, it reduces to linear interpolation.
Given a set of known samples , , the
problem is to find the unique order polynomialwhich interpolates the samples.5.2The solution can be expressed as
a linear combination of elementary th order polynomials:
(5.6)
where
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 11/23
11
PROGRAM GUIDE
1.
Double click on the LAGRANGE.exe to launch the program.
2.
In the program window, input the number of x desired (maximum of
20 inputs only), then press Enter. (see Figure 3-1)
Figure 3-1
3.
Key in the values for xn and f(x)n. Use space to separate xn and f(x)n,
such that xn<space>f(x)n. Press Enter after each pair of digits is putin. (see Figure 3-2)
Figure 3-2
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 12/23
12
4.
Type in the value for x in order to solve for P(x). (see Figure 3-3)
Figure 3-3
5.
Press Enter. The resulting value for P(x) will be shown on the program
window. (see Figure 3-4)
Figure 3-4
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 13/23
13
SOURCE CODE
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#include<conio.h>
#include<stdlib.h>
main()
{
int n;
int i,j,k,;
float mx[10],my[10];
float x,h,x0=0,fun=0,p;
float y0,sum=0,diff[20][20];
float y1,y2,y3,y4;
printf("\n\n\t NEWTON'S BACKWARD INTERPOLATION FORMULA");
printf("\n\n Enter the number of x you want to enter ->");
scanf("%d",&n);
printf("\n\n Enter the values of x ");
for(i=0;i<n;i++)
{
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 14/23
14
printf("\n\n\t Enter the value of x[%d] : ",i+1);
scanf("%f",&mx[i]);
}
printf("\n\n Enter the values of f(x) ");
for(i=0;i<n;i++)
{
printf("\n\n\t Enter the value of f(x)[%d] : ",i+1);
scanf("%f",&my[i]);
}
printf("\n\n Enter the value of x for which you want thevalue of f(x) : ");
scanf("%f",&x);
// Calculation and processing section.
h=mx[1]-mx[0];
for(i=0;i<n-1;i++)
diff[i][1]=my[i+1]-my[i];
for(j=2;j<=4;j++)
for(i=0;i<n-j;i++)
diff[i][j]=diff[i+1][j-1]-diff[i][j-1];
i=0;
while(!mx[i]>x)
i++;
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 15/23
15
x0=mx[i];
sum=0;
y0=my[i];
fun=1;
p=(x-x0)/h;
sum=y0;
for(k=1;k<=4;k++)
{
fun=(fun*(p-(k-1)))/k;
sum=sum+fun*diff[i][k];
}
// Output
printf("\n When x = %6.4f , P(x) = %6.4f\n\n",x,sum);
getch();
system("pause");
}
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 16/23
16
2.
DIVIDED DIFFERENCE
In mathematics, divided differences is a recursive division process. Themethod can be used to calculate the coefficients in the interpolationpolynomial in the Newton form.
The divided difference , sometimes alsodenoted (Abramowitz and Stegun 1972), on points, , ..., of a function is defined by and
(1)
for . The first few differences are
(2)
(3)
(4)
Defining
(5)
and taking the derivative
(6)
gives the identity
(7)
Consider the following question: does the property
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 17/23
17
(8)
for and a given function guarantee that is a polynomial ofdegree ? Aczél (1985) showed that the answer is "yes" for , and
Bailey (1992) showed it to be true for with differentiable .Schwaiger (1994) and Andersen (1996) subsequently showed the answerto be "yes" for all with restrictions on or .
PROGRAM GUIDE
1.
Double click on the DIVIDED DIFFERENCE.exe to launch the
program.
2.
In the program window, input the number of x desired (maximum of10 digits only), then press Enter. (see Figure 4-1)
Figure 4-1
3.
Key in the values for xn and f(x)n while pressing Enter after each digitis put in. (see Figure 4-2)
Figure 4-2
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 18/23
18
4.
Ty
pe in the value for x in order to solve for P(x). (see Figure 4-3)
Figure 4-3
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 19/23
19
5.
Press Enter. The resulting value for P(x) will be shown on the program
window. (see Figure 4-4)
Figure 4-4
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 20/23
20
SOURCE CODE
#include<iostream.h>
#include<stdio.h>#include<conio.h>
#include<math.h>
main()
{
float x[10],y[10][10],sum,p,u,temp;
int i,n,j,k=0,f,m;
system("cls");
float fact(int);
printf("\nEnter number of x: ");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("\n\nEnter the value of x%d: ",i);
scanf("%f",&x[i]);
printf("\n\nEnter the value of f(x%d): ",i);
scanf("%f",&y[k][i]);
}
printf("\n\nEnter value of x for finding P(x): ");
scanf("%f",&p);
for(i=1;i<n;i++)
{
k=i;
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 21/23
21
for(j=0;j<n-i;j++)
{
y[i][j]=(y[i-1][j+1]-y[i-1][j])/(x[k]-x[j]);
k++;
}
}
printf("\n_____________________________________________________\n");
printf("\n x(i)\t y(i)\t y1(i) y2(i)y3(i) y4(i)");
printf("\n_____________________________________________________\n");
for(i=0;i<n;i++)
{
printf("\n %.3f",x[i]);
for(j=0;j<n-i;j++)
{
printf(" ");
printf(" %.3f",y[j][i]);
}
printf("\n");
}
i=0;
do
{
if(x[i]<p && p<x[i+1])
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 22/23
22
k=1;
else
i++;
}while(k != 1);
f=i;
sum=0;
for(i=0;i<n-1;i++)
{
k=f;
temp=1;
for(j=0;j<i;j++)
{
temp = temp * (p - x[k]);
k++;
}
sum = sum + temp*(y[i][f]);
}
printf("\n\nP(%.2f) = %f ",p,sum);
getch();
}
7/18/2019 Users Guide
http://slidepdf.com/reader/full/users-guide-56d607e40160c 23/23
23
REFERENCES
http://en.wikipedia.org/wiki/Polynomial_interpolation
http://mathworld.wolfram.com/NewtonsForwardDifferenceFormula.
html
http://mathworld.wolfram.com/NewtonsBackwardDifferenceFormul
a.html
http://mathworld.wolfram.com/DividedDifference.html
http://mat.iitm.ac.in/home/sryedida/public_html/caimna/interpolat
ion/nbdf.html
http://mathworld.wolfram.com/VandermondeMatrix.html