Your SlideShare is downloading. ×
  • Like
week-22x
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply
Published

 

Published in Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
154
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
1
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. /* Write C program to implement the Newton- Gregory forward interpolation.*/#include<stdio.h>#include<conio.h>#define MaxN 100#define Order_of_diff 4void main (){float arr_x[MaxN+1], arr_y[MaxN+1], numerator=1.0, denominator=1.0, x, y, p, h,diff_table[MaxN+1][Order_of_diff+1];int i,j,n,k;clrscr();printf("Enter the value of n n");scanf("%d",&n);printf("Enter the values of x and y");for(i=0; i<=n; i++)scanf("%f%f", &arr_x[i], &arr_y[i]);printf("Enter the value of x at which value of y is to be calculated");scanf("%f", &x);h=arr_x[1]-arr_x[0];for(i=0; i<=n-1; i++)
  • 2. diff_table[i][1]=arr_y[i+1]-arr_y[i];/*Creating the difference table and calculating first orderdifferences*/for(j=2; j<=Order_of_diff; j++)/*Calculating higher order differences*/for(i=0; i<=n-j; i++)diff_table[i][j]=diff_table[i+1][j-1] - diff_table[i][j-1];i=0;while(!(arr_x[i]>x)) /* Finding x0 */i++;i--;p=(x-arr_x[i])/h;y=arr_y[i];for (k=1; k<=Order_of_diff; k++){ numerator *=p-k+1; denominator *=k; y +=(numerator/denominator)*diff_table[i][k];}printf("When x=%6.1f, y=%6.2fn",x, y);getch();}
  • 3. /* Write C program to implement the Lagrange interpolation.*/#include<stdio.h>#include<conio.h>#define MaxN 90void main(){float arr_x[MaxN+1], arr_y[MaxN+1], numerator, denominator, x, y=0;int i, j, n;clrscr();printf("Enter the value of n: n");scanf("%d", &n);printf("Enter the values of x and y: n");for(i=0; i<=n; i++)scanf("%f%f", &arr_x[i], &arr_y[i]);printf("Enter the value of x at which value of y is to be calculated: ");scanf("%f", &x);for (i=0; i<=n; i++){ numerator=1; denominator=1; for (j=0; j<=n; j++)
  • 4. if(j!=i) { numerator *= x-arr_x[j]; denominator *= arr_x[i]-arr_x[j]; } y+=(numerator/denominator)*arr_y[i];}printf("When x=%4.1f y=%7.1fn",x,y);getch();}