Browse Source

partially fixed (not enough order of convergence)

netstandard
Yoonku Hwang 11 years ago
parent
commit
467717436b
  1. 9
      src/Numerics/OdeSolvers/AdamsBashforth.cs
  2. 4
      src/UnitTests/OdeSolvers/OdeSolverTest.cs

9
src/Numerics/OdeSolvers/AdamsBashforth.cs

@ -65,19 +65,22 @@ namespace MathNet.Numerics.OdeSolvers
/// <param name="N">Number of subintervals</param>
/// <param name="f">ode model</param>
/// <returns></returns>
public static double[] SecondOrder(double y0, double y1, double start, double end, int N, Func<double, double, double> f)
public static double[] SecondOrder(double y0, double start, double end, int N, Func<double, double, double> f)
{
double dt = (end - start) / (N - 1);
double t = start;
double[] y = new double[N];
double k1 = f(t, y0);
double k2 = f(t + dt, y0 + dt * k1);
double y1 = y0 + 0.5 * dt * (k1 + k2);
y[0] = y0;
t += dt;
y[1] = y1;
for (int i = 2; i < N; i++)
{
y1 = f(t + dt, y1);
y[i] = y1 + dt * (1.5 * f(t + dt, y1) - 0.5 * f(t, y0));
t += dt;
y0 = y1;
y0 = y[i-1];
y1 = y[i];
}
return y;

4
src/UnitTests/OdeSolvers/OdeSolverTest.cs

@ -72,9 +72,7 @@ namespace MathNet.Numerics.UnitTests.OdeSolvers
for (int k = 0; k < 4; k++)
{
double y0 = 0;
int N = Convert.ToInt32(Math.Pow(2, k + 6));
double dt = 2.0 / (N - 1);
double[] y_t = AdamsBashforth.SecondOrder(y0, sol(dt), 0, 2, N, ode);
double[] y_t = AdamsBashforth.SecondOrder(y0, 0, 2, Convert.ToInt32(Math.Pow(2, k + 6)), ode);
error = Math.Abs(sol(2) - y_t.Last());
if (oldError != 0)
ratio = Math.Log(oldError / error, 2);

Loading…
Cancel
Save