0

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

G. Church
  • 15
  • 3
  • `u` and `du` are vectors. See if using their scalar contents `u[1]` and `du[1]` in the scalar expression improves the situation. – Lutz Lehmann May 22 '23 at 04:25
  • @Lutz Lehmann Thanks for the prompt reply. Your suggestion did resolve the issue and produced a non-constant solution for u(t). Thanks. – G. Church May 22 '23 at 17:15

0 Answers0