0% found this document useful (0 votes)
90 views

Unit 3 Interpolation: Viral Shah (S/W Projects in C++) Shri Sunshine Group of

The document describes algorithms for interpolation methods in C++. It includes the construction of forward and backward difference tables, Newton's forward and backward interpolation, and Lagrange's interpolation method. The algorithms take in observational data, construct difference tables, and calculate interpolated y-values for given x-values using the different techniques.

Uploaded by

Nirav Gohel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Unit 3 Interpolation: Viral Shah (S/W Projects in C++) Shri Sunshine Group of

The document describes algorithms for interpolation methods in C++. It includes the construction of forward and backward difference tables, Newton's forward and backward interpolation, and Lagrange's interpolation method. The algorithms take in observational data, construct difference tables, and calculate interpolated y-values for given x-values using the different techniques.

Uploaded by

Nirav Gohel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Unit 3 Interpolation

Construction of Forward Difference Table Observation X & Y are stored in 1Dimensional array of size N. A 2 Dimensional array i.e. D is taken to store the forward differences of size N*N. Step 1 [Input No.of Observations]
Read n

Step 2[Input the value of X & Y.]


for i=1 to n by 1 do Read xi Read yi Endfor

Step 3[Construct Forward difference Table: - Calculate the forward difference & store it in d]
For j=1 to n-1 by 1 do For i=1 to n-j by 1 do If j=1 then Set dij=y(i+1) yi Else Set dij=d(i+1)(j-1) d(i)(j-1) Endif Endfor Endfor

Step 4[Display the Forward difference Table]


For i=1 to n by 1 do Write xi,yi For j=1 to n-i by 1 do Write d(i)(j) Endfor Endfor Write xn,yn

Step 5[Stop]
End

1 Viral Shah (S/W PROJECTS IN C++) SHRI SUNSHINE GROUP OF


INSTITUTIONS,RAJKOT

Construction of Backward Difference Table Observation X & Y are stored in 1d array of size N. A 2d array D is taken to store the backward differences of size N*N. Step 1[Read No.of Observations]
Read n

Step 2 [Read the value of X & Y.]


for i=1 to n by 1 do Read xi Read yi Endfor

Step 3[Backward difference Table: - Calculate the backward differences & store it in d]
For j=1 to n-1 by 1 do For i=j+1 to n by 1 do If j=1 then Set dij=y(i) y(i-1) Else Set dij=d (i)(j-1) d (i-1)(j-1) Endif Endfor Endfor

Step 4[Display the Forward difference Table]


For i=1 to n by 1 do Write xi, yi For j=1 to i by 1 do Write dij Endfor Endfor

Step 5 [Stop]
End

2 Viral Shah (S/W PROJECTS IN C++) SHRI SUNSHINE GROUP OF


INSTITUTIONS,RAJKOT

Newton Forward Interpolation Observation X & Y are stored in 1d array of size N. A 2d array D is taken to store the forward differences of size N*N.NEW is 1d array for store the first row of F.D.T Step 1[Read no. of data points and read the value of Xp(Value for find Y)]
Read n, xp

Step 2 [Read the value of X and Y]


for i=1 to n by 1 do Read xi, yi Endfor

Step 3[Check whether x lies bt. x1 and xn]


If x<x1 or x>xn then Write: Value lies outside tabulated range Goto step 8 Endif

Step 4[calculate the value of h and p]


set h=x2-x1 set p= (x-x0)/h

Step 5 [Forward difference Table: - Calculate the forward difference table & store it in d]
For j=1 to n-1 by 1 do For i=1 to n-j by 1 do If j=1 then Set dij=y(i+1) y(i) Else Set dij=d (i+1)(j-1) d(i) (j-1) Endif Endfor Endfor

Step 6[Display TABLE]


For i=1to n by 1 do Write xi,yi For j=1to n-i by 1 do Write dij Endfor Endfor

Step 7[Store first row of forward difference table in 1d array]


For i=1 to n by 1 do Set newi=d1i Endfor

Step 8[find the value of Yp]


Set yp=y(1) For i=1 to n by 1 do 3 Viral Shah (S/W PROJECTS IN C++) SHRI SUNSHINE GROUP OF
INSTITUTIONS,RAJKOT

Set temp=1 Set fact =1 For j=1 to i by 1 do Set temp=temp*(p-(j-1)) Set fact=fact*(j) Endfor Set yp=yp+(newi*temp)/fact Endfor

Step 9[Display the value of Yp]


Write : yp

Step 10 [Stop]
End

Newton Backward Interpolation Observation X & Y are stored in 1d array of size N. A 2d array D is taken to store the backward differences of size N*N.NEW is 1d array for store the first row of B.D.T Step 1[Read no. of data points and read the value of Xp(Value for find Y)]
Read n, xp

Step 2[Read the value of X and Y]


for i=1 to n by 1 do Read xi, yi Endfor

Step 3[Check whether x lies bt. x1 and xn]


If x<x1 or x>xn then Write: Value lies outside tabulated range Goto step 8 Endif

Step 4[caluate the value of h and p]


set h=x2-x1 set p=x-xn/h

Step 5[Backward difference Table: - Calculate the backward difference table & store it in d]
For j=1 to n-1 by 1 do For i=j+1 to n by 1 do If j=1 then Set dij=yi yi-1 Else Set dij=d (i)(j-1) d(i-1)(j-1) Endif Endfor 4 Viral Shah (S/W PROJECTS IN C++) SHRI SUNSHINE GROUP OF
INSTITUTIONS,RAJKOT

Endfor

Step 6[Display TABLE]


For i=1to n by 1 do Write xi,yi For j=1to i-1 by 1 do Write dij Endfor Endfor

Step 7[Store first row of backward difference table in 1d array]


For i=1 to n by 1 do Set Newi=dni Endfor

Step 8[find the value of Yp]


Set yp=yn For i=1 to n by 1 do Set temp=1 Set fact =1 For j=i to 1 by -1 do Set temp=temp*(p+j) Set fact=fact*(j+1) Endfor Set yp=yp+(newi*temp)/fact Endfor

Step 9[Display the value of Yp]


Write yp

Step 10 [Stop]
End

5 Viral Shah (S/W PROJECTS IN C++) SHRI SUNSHINE GROUP OF


INSTITUTIONS,RAJKOT

Lagranges Interpolation Method In order to find interpolation value using langrage's methods. We use to store the observation in single dimension array say x & y of size n. Step 1 [Read number of observation]
Read n

Step 2 [Read the value of x and y]


For i=1 to n by 1 do Read xi, yi Endfor

Step 3 [Read the value of xp]


Read xp

Step 4 [Calculate the value of yp]


For i=1 to n-1 by 1 do Set p=1 For j=1 to n-1 by 1 do If i<>j then Set P=P*(xp-xj)/xi-xj Endif Endfor Set sum=sum+yi*p Endfor

Step 5 [display the value of yp]


Write Interpolated Value=,sum

Step 6 [Stop]
End

6 Viral Shah (S/W PROJECTS IN C++) SHRI SUNSHINE GROUP OF


INSTITUTIONS,RAJKOT

You might also like