Skip to content
DeepForgeby svx
All problems
EasyCalculusca-266

Backward Euler Step

Problem

The backward (implicit) Euler method applied to y' = lam*y gives y_next = y / (1 - h*lam).

Given the current value y, the step size h, and the rate lam with h*lam != 1, return y_next. Unlike forward Euler, the method is stable for any step size when lam < 0.

Hint

The implicit update solves y_next = y + h*lam*y_next for y_next.

Test cases

case 1
in: [1,0.1,-2]
expected: 0.8333333333333334
case 2
in: [1,0.1,0]
expected: 1
case 3
in: [2,0.5,1]
expected: 4
case 4
in: [1,0.1,2]
expected: 1.25
Starter codePython
def backward_euler_step(y, h, lam):
    # Your code here
    pass

4 test cases · run your code against them in the editor