Mathsassignment
Mathsassignment
I. INTRODUCTION
{
// Number of values given Backward Differences
int n = 4; The differences y1 – y0, y2 – y1, ……, yn – yn–1
float x[] = { 45, 50, 55, 60 }; when denoted by dy1, dy2, ……, dyn, respectively,
// y[][] is used for difference table are named as first backward difference. Thus the first
// with y[][0] used for input backward differences are :
float y[n][n];
y[0][0] = 0.7071;
y[1][0] = 0.7660;
y[2][0] = 0.8192;
y[3][0] = 0.8660;
// Calculating the forward difference
// table
for (int i = 1; i < n; i++) {
for (int j = 0; j < n - i; j++)
y[j][i] = y[j + 1][i - 1] - y[j][i - 1];
}
// Displaying the forward difference table
for (int i = 0; i < n; i++) {
III. NEWTON’S GREGORY BACKWARD
cout << setw(4) << x[i]
INTERPOLATION FORMULA
<< "\t";
for (int j = 0; j < n - i; j++)
This formula is used when the value of f(x) is
cout << setw(4) << y[i][j]
required at the end of the table. h is known as the
<< "\t"; common difference and u = ( x – an ) / h, Here an is
cout << endl; last term in table.[3]
}
// Value to interpolate at Example:Input: Population in 1925
float value = 52;
// initializing u and sum Year(x): 1891 1901 1911 1921 1931
float sum = y[0][0]; Population(y): 46 66 81 93 101
float u = (value - x[0]) / (x[1] - x[0]); (in thousands)
for (int i = 1; i < n; i++) {
sum = sum + (u_cal(u, i) * y[0][i]) /
Output:
fact(i);
}
cout << "\n Value at " << value << " is "
<< sum << endl;
return 0;
}
ACKNOWLEDGEMENT
REFERENCES