1

I am fairly new to Julia, so apologies in advance. I am trying to simultaneously solve two differential equations in Julia and having trouble. I have a MWE in Python, which is:

import numpy as np
from scipy import solve_ivp

def derivatives(T,y):
    
    T𝜈 = y[0]
    t = y[1]
    
    dtdT = T**2
    dT𝜈dT = T𝜈**2
    
    return dT𝜈dT, dtdT

def solver(Ti, Tf, n):
    
    t_eval = np.geomspace(Ti, Tf, n)
    t_span = [Ti, Tf]
    y0 = [Ti, 0]

    TSolved = solve_ivp(derivatives, t_span, y0, t_eval)
    
    return TSolved.t, TSolved.y[0], TSolved.y[1]

This works and behaves how I would like it to. I've tried doing the following in Julia (same problem), and it gives me trouble:

using DifferentialEquations

function Derivatives(T,y)

   T𝜈 = y[1]
   t = y[2]
 
   dtdT = T^2
   dT𝜈dT = T𝜈^2
   
   return dT𝜈dT, dtdT
 
end

function Solver(Ti, Tf, n)
   
    saveat = vec(10 .^ range(log(Ti), log(Tf), length=n))
    TSpan = (Ti, Tf)
    T0 = (Ti, 0)
    DiffEq = ODEProblem(Derivatives, TSpan, T0)
    Solution = solve(DiffEq, saveat=saveat)
    
    return Solution

end

No matter how I edit it, I am getting a MethodError in Julia. I believe the problem is with how I am handling/inputting vectors and arrays, but I'm not at a bit of a loss. TIA!

1
  • Have you actually tried to run the Python version? I get an error trying it (Python 3.9.7) Commented May 26, 2022 at 17:17

1 Answer 1

0

"Solving IVP with vectors", the issue is that you aren't using any vectors here. return dT𝜈dT, dtdT isn't a vector, it's a tuple.

function Derivatives(T,y)

   T𝜈 = y[1]
   t = y[2]
 
   dtdT = T^2
   dT𝜈dT = T𝜈^2
   
   return [dT𝜈dT, dtdT]
 
end

will be fine. Well, also make sure the ODEProblem is defined as ODEProblem(f,u0,tspan): you flipped the time span definition and initial condition (DiffEq = ODEProblem(Derivatives, T0, TSpan))

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.