예제 #1
0
    'A': (lambda t, x: x['A'] + 1),
    'B': (lambda t, x: x['A'] + x['B']),
    'C': (lambda t, x: 2 * x['B'])
}

initial_values = {'A': 0, 'B': 0, 'C': 0}
initial_point = (0, initial_values)
euler = EulerEstimator(derivatives=derivatives)

assert euler.calc_derivative_at_point(initial_point) == {
    'A': 1,
    'B': 0,
    'C': 0
}

point_2 = euler.step_forward(initial_point, 0.1)
assert point_2 == (0.1, {'A': 0.1, 'B': 0, 'C': 0}), point_2

assert euler.calc_derivative_at_point(point_2) == {
    'A': 1.1,
    'B': 0.1,
    'C': 0
}, euler.calc_derivative_at_point(point_2)

point_3 = euler.step_forward(point_2, -0.5)
assert point_3 == (-0.4, {'A': -0.45, 'B': -0.05, 'C': 0}), point_3

assert euler.calc_estimated_points(point_3, 2, 3) == [(-0.4, {
    'A': -0.45,
    'B': -0.05,
    'C': 0.0
예제 #2
0
euler = EulerEstimator(
    derivatives={
        '1': (lambda t, x: x['1'] + 1),
        '2': (lambda t, x: x['1'] + x['2']),
        '3': (lambda t, x: 2*x['2'])
    },
    point=(0, {'1': 0, '2': 0, '3': 0})
)

do_assert("point", euler.point,
          (0, {'1': 0, '2': 0, '3': 0}))
do_assert("calc derivative", euler.calc_derivative_at_point(),
          {'1': 1, '2': 0, '3': 0})

euler.step_forward(0.1)
do_assert("step forward", euler.point,
          (0.1, {'1': 0.1, '2': 0, '3': 0}))

do_assert("new derivative", euler.calc_derivative_at_point(),
          {'1': 1.1, '2': 0.1, '3': 0})
euler.step_forward(-0.5)
do_assert("step forward 2", euler.point,
          (-0.4, {'1': -0.45, '2': -0.05, '3': 0}))

euler.go_to_input(5, step_size=2)

# notes to help you debug:

# point: (-0.4, (-0.45, -0.05, 0))
# derivative: (0.55, -0.5, -0.1)
예제 #3
0
    'B': (lambda t, x: x['A'] + x['B']),
    'C': (lambda t, x: 2 * x['B'])
}

euler = EulerEstimator(derivatives=derivatives)

initial_values = {'A': 0, 'B': 0, 'C': 0}
initial_point = (0, initial_values)

assert euler.calc_derivative_at_point(initial_point) == {
    'A': 1,
    'B': 0,
    'C': 0
}

point_2 = euler.step_forward(point=initial_point, step_size=0.1)
assert point_2 == (0.1, {'A': 0.1, 'B': 0, 'C': 0})

assert euler.calc_derivative_at_point(point_2) == {'A': 1.1, 'B': 0.1, 'C': 0}

point_3 = euler.step_forward(point=point_2, step_size=-0.5)
assert point_3 == (-0.4, {'A': -0.45, 'B': -0.05, 'C': 0})

assert euler.calc_estimated_points(point=point_3, step_size=2,
                                   num_steps=3) == [
                                       (-0.4, {
                                           'A': -0.45,
                                           'B': -0.05,
                                           'C': 0
                                       }),  # starting point 
                                       (1.6, {