Write C program to implement the Newton- Gregory forward interpolation
.
Algorithm:
Step1: START Step2: Read n Step3: for i = 0 to (n-1) do read xi, yi Step4: read x Step5: h ← xi-x0 Step6: p ← (x - xo)/n Step7: for j = 0 to n-2 do Δ1yj ← yj + 1 - Δi - 1 Step8: k ← n - 2 Step9: for i = 2 to (n - 1) do Step9.1: k ← k - 1 Step9.2: for j = 0 to k do Δiyj ← Δi - 1 yj + 1 - Δi - 1yj Step10: Sumy ← y0 Step11: Pvalue ← 1 Step12: Fact value ← 1 Step13: for l = 1 to (n - 1) do Step13.1: Pvalue ← pvalue x (p - (l - 1)) Step13.2: factvalue ← factvaluex1 Step13.3: term ← (pvalue x Δly) / factvalue Step13.4: Sumy ← Sumy + term Step14: Print x, SUMY Step15: STOP
Flowchart:
Program:
#include<stdio.h> #include<math.h> main() { int i, j, n, k, l; float sumy, h, term, p, z, pvalue; float x[25], y[25], d[25][25], factvalue; printf(“enter the value of n”); scanf(“%d”, &n); printf(“enter %d values for x, y \n”, n); for(i = 0; i < n; i++) scanf(“%f %f”, &x[i], &y[i]); printf(“\n enter z”); scanf(“%f”, &z); h = x[1] – x[0]; p = (z - x[0] )/ h; for(j = 0; j < n-2; j++) d[i][j] = y[j + 1] – y[j]; k = n-2; for(i = 2; i < n; i++) { k++; for(j = 0; j <= k; j++) d[i][j] = d[i - 1][j + 1] – d[i - 1][j]; } for(l = 1; l < n; l++) { pvalue *= (p - (l - 1)); factvalue *= 1; term = pvalue * d[l][0] / factvalue; sumy += term; } printf(“\n y value at z = %f is %f”, z, sumy); }
Input & Output:
enter n 7 enter 7 data values for x, y 1921 35 1931 42 1941 58 1951 84 1961 120 1971 165 1981 220 enter z 1925 y value at z = 1925.000000 is 36.756710
-
UpdatedOct 21, 2014
-
Views19,071
You May Like
Write a C program to find the roots of a quadratic equation
.
Write a C program to count the lines, words and characters in a given text.
Write a C program to find the sum of individual digits of a positive integer.
Write a C program, which takes two integer operands and one operator from the user, performs the operation and then prints the result. (Consider the operators +,-,*, /, % and use switch statement
)
Write a C program to generate all the prime numbers
between 1 and n, where n is a value supplied by the user.
Write C programs that use both recursive
and non-recursive functions
- To find the
factorial
of a given integer. - To find the
GCD
(greatest common divisor) of two given integers.