All problems
Homogeneous ODE Solution Value
Problem
Solve y'' + p*y' + q*y = 0 for the real distinct characteristic roots r1 != r2 with initial conditions y(0) = y0 and y'(0) = v0.
The solution is y(t) = C1*e^(r1*t) + C2*e^(r2*t) with C1 = (v0 - r2*y0) / (r1 - r2) and C2 = y0 - C1. Return y(t).
Hint
The constants follow from y(0) = C1 + C2 and y'(0) = r1*C1 + r2*C2.
Test cases
case 1
in: [0,1,0,-1,-2]
expected: 1
case 2
in: [1,1,0,-1,-2]
expected: 0.600423599106272
case 3
in: [1,0,1,1,3]
expected: 8.683627547364312
case 4
in: [2,2,-1,-1,1]
expected: 3.897530974320244
Starter codePython
def homogeneous_ode_value(t, y0, v0, r1, r2):
# Your code here
pass4 test cases · run your code against them in the editor