To Construct the New Data Points Using Laplace Everett's Method of Interpolation - C Data Structure

C examples for Data Structure:Algorithm

Description

To Construct the New Data Points Using Laplace Everett's Method of Interpolation

Demo Code

#include <stdio.h>
#define MAX 20/*w w  w.j a  v a2s .co  m*/

int main()
{
  int i, j, terms = 10;
  float ax[MAX], ay[MAX], x, y = 0, h, p, q;
  float diff[MAX][5], y1, y2, y3, y4, py1, py2, py3, py4;
  
  printf("\nEnter the values of x upto 2 decimal points.\n");
  
  for (i=0; i<terms; i++) {
    printf("Enter the value of x%d: ", i+1);
    scanf("%f",&ax[i]);
  }
  printf("\nNow enter the values of y upto 4 decimal points.\n");
  for (i=0; i < terms; i++) {
    printf("Enter the value of y%d: ", i+1);
    scanf("%f", &ay[i]);
  }

  x = 20;
  h = ax[1] - ax[0];
  for(i=0; i < terms-1; i++)
    diff[i][1] = ay[i+1] - ay[i];
  for(j=2; j <= 4; j++)
    for(i=0; i < terms-j; i++)
      diff[i][j] = diff[i+1][j-1] - diff[i][j-1];
  i = 0;
  do {
    i++;
  } while(ax[i] < x);
  i--;
  p = (x - ax[i])/h;
  q = 1 - p;
  y1 = q * (ay[i]);
  y2 = q * (q*q-1) * diff[i-1][2]/6;
  y3 = q * (q*q-1) * (q*q-4) * (diff[i-2][4])/120;
  py1 = p * ay[i+1];
  py2 = p * (p*p-1) * diff[i][2]/6;
  py3 = p * (p*p-1) * (p*p-4) * (diff[i-1][4])/120;
  y = y1 + y2 + y3 + y4 + py1 + py2 + py3;
  printf("\nFor x = %6.2f,     y = %6.4f ", x, y);
}

Related Tutorials