Skip to content
DeepForgeby svx
All problems
HardCalculusca-137

Bernoulli ODE Substitution Value

Problem

Solve the Bernoulli equation y' + p*y = q*y^n with y(0) = y0 where n != 1 and y0 > 0.

The substitution v = y^(1-n) gives a linear equation whose solution is v = q/p + (v0 - q/p)*e^(-(1-n)*p*x) when p != 0, and v = v0 + (1-n)*q*x when p == 0, with v0 = y0^(1-n). Return y(x) = v^(1/(1-n)).

Hint

The substitution linearizes the equation, then invert it at the end.

Test cases

case 1
in: [1,1,1,0,2]
expected: 0.36787944117144233
case 2
in: [1,0.5,1,1,2]
expected: 0.2689414213699951
case 3
in: [1,1,1,2,0]
expected: 1.6321205588285577
case 4
in: [0.25,1,0,1,3]
expected: 1.4142135623730951
Starter codePython
def bernoulli_value(x, y0, p, q, n):
    # Your code here
    pass

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