Mercurial > octave-nkf
comparison scripts/ode/private/hermite_quartic_interpolation.m @ 20584:eb9e2d187ed2
maint: Use Octave coding conventions in scripts/ode/private dir.
* AbsRel_Norm.m, fuzzy_compare.m, hermite_quartic_interpolation.m,
integrate_adaptive.m, integrate_const.m, integrate_n_steps.m, kahan.m,
ode_struct_value_check.m, odepkg_event_handle.m, odepkg_structure_check.m,
runge_kutta_45_dorpri.m, starting_stepsize.m:
Wrap long lines to < 80 chars.
Use double quotes rather than single quotes where possible.
Use ';' at end of keywords "return;" and "break;"
Use '##" for stand-alone comments and '#' for end-of-line comments.
Use two spaces after period before starting new sentence.
Use '!' instead of '~' for logical negation.
Use specific form of end (endif, endfor, etc.).
Don't use line continuation marker '...' unless necessary.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 04 Oct 2015 22:18:54 -0700 |
parents | 25623ef2ff4f |
children |
comparison
equal
deleted
inserted
replaced
20583:d746695bf494 | 20584:eb9e2d187ed2 |
---|---|
15 ## You should have received a copy of the GNU General Public License | 15 ## You should have received a copy of the GNU General Public License |
16 ## along with Octave; see the file COPYING. If not, see | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {[@var{x_out}] =} hermite_quartic_interpolation (@var{t}, @var{x}, @var{der}, @var{t_out}) | 20 ## @deftypefn {Function File} {@var{x_out} =} hermite_quartic_interpolation (@var{t}, @var{x}, @var{der}, @var{t_out}) |
21 ## | 21 ## |
22 ## This function file can be called by an ODE solver function in order to | 22 ## This function file can be called by an ODE solver function in order to |
23 ## interpolate the solution at the time @var{t_out} using 4th order | 23 ## interpolate the solution at the time @var{t_out} using a 4th order |
24 ## Hermite interpolation. | 24 ## Hermite interpolation. |
25 ## | 25 ## |
26 ## This function must be called with one output arguments: @var{x_out} | 26 ## The first input @var{t} is a vector with two given times. |
27 ## which contains the evaluation at @var{t_out} of the Hermite interpolant. | |
28 ## | |
29 ## The first input argument is the vector with two given times. | |
30 ## | 27 ## |
31 ## The second input argument is the vector with the values of the function | 28 ## The second input argument is the vector with the values of the function |
32 ## to interpolate at the times specified in @var{t} and at the middle point. | 29 ## to interpolate at the times specified in @var{t} and at the middle point. |
33 ## | 30 ## |
34 ## The third input argument is the value of the derivatives of the function | 31 ## The third input argument is the value of the derivatives of the function |
35 ## evaluated at the two extreme points. | 32 ## evaluated at the two extreme points. |
33 ## | |
34 ## The output @var{x_out} is the evaluation of the Hermite interpolant at | |
35 ## @var{t_out}. | |
36 ## | 36 ## |
37 ## @end deftypefn | 37 ## @end deftypefn |
38 ## | 38 ## |
39 ## @seealso{linear_interpolation, quadratic_interpolation, | 39 ## @seealso{linear_interpolation, quadratic_interpolation, |
40 ## hermite_cubic_interpolation, hermite_quintic_interpolation, | 40 ## hermite_cubic_interpolation, hermite_quintic_interpolation, |
41 ## dorpri_interpolation} | 41 ## dorpri_interpolation} |
42 | 42 |
43 function x_out = hermite_quartic_interpolation (t, x, der, t_out) | 43 function x_out = hermite_quartic_interpolation (t, x, der, t_out) |
44 | 44 |
45 # Rescale time on [0,1] | 45 ## Rescale time on [0,1] |
46 s = (t_out - t(1)) / (t(2) - t(1)); | 46 s = (t_out - t(1)) / (t(2) - t(1)); |
47 | 47 |
48 # Hermite basis functions | 48 ## Hermite basis functions |
49 # H0 = 1 - 11*s.^2 + 18*s.^3 - 8*s.^4; | 49 ## H0 = 1 - 11*s.^2 + 18*s.^3 - 8*s.^4; |
50 # H1 = s - 4*s.^2 + 5*s.^3 - 2*s.^4; | 50 ## H1 = s - 4*s.^2 + 5*s.^3 - 2*s.^4; |
51 # H2 = 16*s.^2 - 32*s.^3 + 16*s.^4; | 51 ## H2 = 16*s.^2 - 32*s.^3 + 16*s.^4; |
52 # H3 = - 5*s.^2 + 14*s.^3 - 8*s.^4; | 52 ## H3 = - 5*s.^2 + 14*s.^3 - 8*s.^4; |
53 # H4 = s.^2 - 3*s.^3 + 2*s.^4; | 53 ## H4 = s.^2 - 3*s.^3 + 2*s.^4; |
54 | 54 |
55 x_out = zeros (size (x, 1), length (t_out)); | 55 x_out = zeros (rows (x), length (t_out)); |
56 for ii = 1:size (x, 1) | 56 for ii = 1:rows (x) |
57 x_out(ii,:) = (1 - 11*s.^2 + 18*s.^3 - 8*s.^4)*x(ii,1) ... | 57 x_out(ii,:) = (1 - 11*s.^2 + 18*s.^3 - 8*s.^4)*x(ii,1) ... |
58 + ( s - 4*s.^2 + 5*s.^3 - 2*s.^4)*(t(2)-t(1))*der(ii,1) ... | 58 + ( s - 4*s.^2 + 5*s.^3 - 2*s.^4)*(t(2)-t(1))*der(ii,1) ... |
59 + ( 16*s.^2 - 32*s.^3 + 16*s.^4)*x(ii,2) ... | 59 + ( 16*s.^2 - 32*s.^3 + 16*s.^4)*x(ii,2) ... |
60 + ( - 5*s.^2 + 14*s.^3 - 8*s.^4)*x(ii,3) ... | 60 + ( - 5*s.^2 + 14*s.^3 - 8*s.^4)*x(ii,3) ... |
61 + ( s.^2 - 3*s.^3 + 2*s.^4)*(t(2)-t(1))*der(ii,2); | 61 + ( s.^2 - 3*s.^3 + 2*s.^4)*(t(2)-t(1))*der(ii,2); |
62 endfor | 62 endfor |
63 | 63 |
64 endfunction | 64 endfunction |
65 | 65 |
66 ## Local Variables: *** | |
67 ## mode: octave *** | |
68 ## End: *** |