julia

BoundsError: attempt to access Float64 at index [false]


I'm trying to use Julia to solve an ODE with the code below:

using DifferentialEquations

const C = 1.1;
const R = 0.9;
const A = 1e-4;
const B = 60/72;

function flow(t)
    bloodflow = A*sin.(2*π*t/B)
    bloodflow[bloodflow.<0] .= 0;
    return bloodflow
end

function pressure(P,p,t)
    return flow(t)/C - P/(C*R)
end

P0 = 90;
tspan = (0,1);
prob = ODEProblem(pressure,P0,tspan)
sol = solve(prob);

But I am getting the following error.

BoundsError: attempt to access Float64 at index [false]

with a very long Stacktrace.

I'm new to Julia and am still figuring stuff out :)


Solution

  • You can define

    flow(t) = max(0, A*sin(2*π*t/B))
    

    The 0 will be promoted to the appropriate float type.