Ejemplo n.º 1
0
def solver(x, ys, step, system: System, table: ButcherTable, end, order,
           error):
    def take_doublestep(_x, _ys, _step):
        _ys += np.array(correction(_x, _ys, system, _step, table))
        _x += _step
        _ys += np.array(correction(_x, _ys, system, _step, table))
        return _ys

    while True:
        if step + x >= end:
            step = end - x
            x = end
        else:
            x += step

        next_ys = ys + correction(x, ys, system, step, table)
        ys_doublestep = take_doublestep(x, ys, step / 2)
        local_error = norm(ys_doublestep - next_ys) / (1 - 2**(-order))

        if local_error > error * 2**order:
            step /= 2
        elif local_error > error:
            step /= 2
            ys = ys_doublestep
        elif local_error > error / 2**(order + 1):
            ys = next_ys
        else:
            step *= 2
            ys = next_ys

        if x >= end:
            break
    return ys
Ejemplo n.º 2
0
def _const_step_solver(x, ys, step, system: System, table: ButcherTable, end):
    while True:
        if step + x >= end:
            step = end - x
            x = end
        else:
            x += step
        ys += correction(x, ys, system, step, table)
        if x >= end:
            break
    return ys
Ejemplo n.º 3
0
 def take_doublestep(_x, _ys, _step):
     _ys += np.array(correction(_x, _ys, system, _step, table))
     _x += _step
     _ys += np.array(correction(_x, _ys, system, _step, table))
     return _ys