Solving a gradient dependet ODE in Julia

190 Views Asked by At

I am trying to solve the following ODE using DifferentialEquation.jl :

enter image description here

Where P is a matrix used for a projection. I am having a hard time imagining how to solve this problem. Is there a way to directly solve it using Julia? Or should I try and rearrange the equation by hand (which I already tried) to fit the usual differential equation format? I already started by writing down some equations which can be found below but I am not getting very far.


function ODE(u, p, t)
    g,N = p
    Jacg = ForwardDiff.jacobian(g, u)
   
    sum = zeros(size(N,1))

    for i in 1:size(Jacg,1)
        sum = sum + Jacg[i,:] .* (u / norm(u)) .* N[:,i]
    end

    Proj_N(N) * sum
    nothing
end

prob = ODEProblem(ODE, u0, (0.0, 3.0), (g, N))
sol = solve(prob)

Any help is appreciated and thanks in advance.

1

There are 1 best solutions below

2
On

If you want to use the out of place form you have to return the derivative, i.e.

function ODE(u, p, t)
    g,N = p
    Jacg = ForwardDiff.jacobian(g, u)
   
    sum = zeros(size(N,1))

    for i in 1:size(Jacg,1)
        sum = sum + Jacg[i,:] .* (u / norm(u)) .* N[:,i]
    end

    Proj_N(N) * sum
end

I think you were just mixing up the mutating and non-mutating derivative forms.