NADCON5-ng  0.0.2
NADCON5 Next Generation Documentation
cubterp.f
Go to the documentation of this file.
1 c> \ingroup core
2 c> \if MANPAGE
3 c> \page cubterp
4 c> \endif
5 c>
6 c> This function fits a cubic function through four points
7 c>
8 c> This function fits a cubic function through
9 c> four *equally* spaced points along the x-axis
10 c> at indices 0, 1, 2 and 3. The spacing along the
11 c> x-axis is "dx"
12 c>
13 c> Thus:
14 c>
15 c> \f{eqnarray*}{
16 c> f0 = f_0 &= y(x_0) \\
17 c> f1 = f_1 &= y(x_1) \\
18 c> f2 = f_2 &= y(x_2) \\
19 c> f3 = f_3 &= y(x_3)
20 c> \f}
21 c>
22 c> Where:
23 c>
24 c> \f{eqnarray*}{
25 c> x_1 &= x_0 + dx \\
26 c> x_2 &= x_1 + dx \\
27 c> x_3 &= x_2 + dx
28 c> \f}
29 c>
30 c> The input value is some value of "x" that falls
31 c> between 0 and 3. The output value (cubterp) is
32 c> the cubic function at x.
33 c>
34 c>
35 c> \param[in] x Compute Interpolation at this positon, a value between 0 and 3
36 c> it is scaled relative to `x_0` `x_3` and `dx`. For example,
37 c> a value of 1.5 is `x_0 + 1.5*dx` which falls between `x1` and `x2`
38 c> \param[in] f0 `y` value at `x_0`
39 c> \param[in] f1 `y` value at `x_1 = x_0 + dx`
40 c> \param[in] f2 `y` value at `x_2 = x_0 + dx`
41 c> \param[in] f3 `y` value at `x_3 = x_0 + dx``
42 c>
43 c> This function uses Newton-Gregory forward polynomial
44 c>
45 c> \f{eqnarray*}{
46 c> \nabla f_0 &=& f_1 -f_0 \\
47 c> \nabla f_1 &=& f_2 -f_1 \\
48 c> \nabla^2 f_0 &=& \nabla f_1 - \nabla f_0 \\
49 c> cubterp(x, f_0, f_1, f_2, f_3) &=& f_0 + x \nabla f_0 + 0.5 x \left( x-1.0 \right) \nabla^2 f_0
50 c> \f}
51  real function cubterp(x,f0,f1,f2,f3)
52 
53 c - x = real*4
54 c - f0,f1,f2,f3 = real*4
55 
56 c - This function fits a cubic function through
57 c - four points, *equally* spaced along the x-axis
58 c - at indices 0, 1, 2 and 3. The spacing along the
59 c - x-axis is "dx"
60 c - Thus:
61 c -
62 c - f0 = y(x(0))
63 c - f1 = y(x(1))
64 c - f2 = y(x(2))
65 c - f3 = y(x(3))
66 c - Where
67 c - x(1) = x(0) + dx
68 c - x(2) = x(1) + dx
69 c - x(3) = x(2) + dx
70 
71 c - The input value is some value of "x" that falls
72 c - between 0 and 3. The output value (cubterp) is
73 c - the cubic function at x.
74 c -
75 c - This function uses Newton-Gregory forward polynomial
76 
77 c df0 =f1 -f0
78 c df1 =f2 -f1
79 c d2f0=df1-df0
80 
81 c qterp=f0 + x*df0 + 0.5*x*(x-1.0)*d2f0
82 
83  df0 = f1 - f0
84  df1 = f2 - f1
85  df2 = f3 - f2
86 
87  d2f0 = df1 - df0
88  d2f1 = df2 - df1
89 
90  d3f0 = d2f1 - d2f0
91 
92  cubterp=f0 + x*df0 + 0.5*x*(x-1.0)*d2f0
93  * +(1.0/6.0)*d3f0*x*(x-1.0)*(x-2.0)
94 
95  return
96  end
real function cubterp(x, f0, f1, f2, f3)
This function fits a cubic function through four points.
Definition: cubterp.f:52