|
Packit |
67cb25 |
/* ode-initval2/rksubs.c
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* Copyright (C) 2008, 2009, 2010 Tuomo Keskitalo
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
67cb25 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
67cb25 |
* the Free Software Foundation; either version 3 of the License, or (at
|
|
Packit |
67cb25 |
* your option) any later version.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is distributed in the hope that it will be useful, but
|
|
Packit |
67cb25 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
67cb25 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
67cb25 |
* General Public License for more details.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
67cb25 |
* along with this program; if not, write to the Free Software
|
|
Packit |
67cb25 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
static int
|
|
Packit |
67cb25 |
rksubs (double y[], const double h, const double y0[], const double fY[],
|
|
Packit |
67cb25 |
const double b[], const size_t stage, const size_t dim)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
/* The final substitution step in Runge-Kutta equation:
|
|
Packit |
67cb25 |
Calculates new values y by substituting the value of step size
|
|
Packit |
67cb25 |
(h), current initial values of y (y0), function f values at
|
|
Packit |
67cb25 |
Runge-Kutta points (fY), Runge-Kutta b-coefficients (b) and
|
|
Packit |
67cb25 |
method stage (stage) into the equation
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
y = y0 + h * sum j=1..stage (b_j * fY_j)
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
dim is the number of ODEs.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
size_t i, j;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
for (i = 0; i < dim; i++)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
y[i] = 0.0;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
for (j = 0; j < stage; j++)
|
|
Packit |
67cb25 |
y[i] += b[j] * fY[j * dim + i];
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
for (i = 0; i < dim; i++)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
y[i] *= h;
|
|
Packit |
67cb25 |
y[i] += y0[i];
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
return GSL_SUCCESS;
|
|
Packit |
67cb25 |
}
|