How can I solve a non-autonomous ODE using DifferentialEquations.jl and Julia

71 views Asked by At

How to solve this autonomous ODE using DifferentialEquations.jl?

I'm using Pluto notebooks for the Differential Equations class I'm teaching this semester.

I'm having problems using DifferentialEquations.jl to solve this non-autonomous ODE:

`u'(t) = (0.1 + 0.2*t)*0.3 - 5*u(t) / (0.01*t^2 - 4.9*t + 400)`

Here's what I tried:

    u0 = [20]
    tspan = (0, 400)

    function salt1(du, u, p, t)
        du = (0.1 + 0.2*t)*0.3 - 5*u / (0.01*t^2 - 4.9*t + 400)
    end

    prob = ODEProblem(salt1, u0, tspan, p)

    sol = solve(prob)

solve gives an error "For element-wise subtraction, use broadcasting with dot syntax: scalar .- array"

When I change the function salt1 to:

    function salt1(du, u, p, t)
        du = (0.1 + 0.2*t)*0.3 .- 5*u / (0.01*t^2 - 4.9*t + 400)
    end

the error goes away, but solve returns a constant function solution for u(t)=u0, which it should not be.

What is wrong with my approach?

Any useful help greatly appreciated.

Thanks, Gary

0

There are 0 answers