All problems
Nonhomogeneous Particular Solution
Problem
For the ODE y'' + p*y' + q*y = A*e^(r*x), a particular solution has the form y_p = A*e^(r*x) / (r^2 + p*r + q), provided the denominator is nonzero (no resonance).
Given p, q, A, r, and the evaluation point x, return y_p(x). If r^2 + p*r + q == 0, return None.
Hint
Substitute the exponential guess into the ODE and solve for the constant.
Test cases
case 1
in: [3,2,1,1,0]
expected: 0.16666666666666666
case 2
in: [0,1,2,0,0]
expected: 2
case 3
in: [1,1,1,0,0]
expected: 1
case 4
in: [3,2,1,1,1]
expected: 0.45304697140984085
case 5
in: [2,1,1,-1,0]
expected: null
Starter codePython
def particular_solution_value(p, q, big_a, r, x):
# Return None on resonance
# Your code here
pass5 test cases · run your code against them in the editor