0% found this document useful (0 votes)
12 views2 pages

Input

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Input

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Input:
 x: This array stores the independent variable values (years in this case)
as [1891 1901 1911 1921 1931].
 y: This array stores the dependent variable values (population in this
case) as [46 66 81 93 101].
 n: This variable calculates the length of the x and y arrays, resulting in n
= 5.
2. Difference Table Creation:
 t: This is a 2D array (matrix) used to construct the forward difference
table. It will be initialized with zeros with dimensions n x (n+1).
 The first column (t(:,1)) of t is populated with the x values.
 The second column (t(:,2)) of t is populated with the y values.
3. Forward Difference Calculation:
 A loop iterates from j = 3 to n+1 (columns 3 to 6 in the difference
table).
 Inside the loop, another loop iterates from i = 1 to dd (rows 1 to 4,
decreasing in each iteration).
o The formula t(i+1,j-1) - t(i,j-1) is used to calculate the forward
differences. This subtracts the value at the previous row and
column from the value at the current row and column.
o The calculated forward difference is stored in t(i,j).
 The variable dd is decremented by 1 in each outer loop iteration to
account for the decreasing number of rows used in the inner loop
calculation. This ensures the forward differences are calculated
correctly across diagonals.
4. Forward Interpolation:
 sumf: This variable is initialized to y(1), which is the first value in the y
array (population in 1891).
 h: This variable calculates the interval between consecutive x values
(years). It's computed as x(2) - x(1), resulting in h = 10.
 vf: This variable represents the value of the independent variable
(year) for which you want to interpolate the dependent variable
(population). In this example, it's set to vf = 1895.
 p: This variable calculates the relative position of vf within the x range.
It's computed as (vf - x(1)) / h, resulting in p = (1895 - 1891) / 10 =
0.4.
 The loop iterates from i = 1 to n-1 (number of terms in the forward
interpolation formula).
 Inside the loop:
o prod: This variable is initialized to 1 and is used to accumulate
the product term in the forward interpolation formula.
o Another loop iterates from j = 1 to i (number of factors in the
product term).
 Inside the inner loop, prod is multiplied by p - (j-1). This
calculates the term p(p-1)(p-2)... in the formula.
 After the inner loop, the calculated product term prod is multiplied by
t(1,i+2) (the appropriate forward difference from the table) and
divided by the factorial of i (factorial(i)). This is added to sumf to
accumulate the interpolated value.
5. Output:
 The code displays a message "Interpolation using Forward Difference
Table".
 Finally, it prints the interpolated value stored in sumf. This represents
the estimated population in 1895 based on the given data and the
forward interpolation method.

You might also like