Original title: “Some help solving set of differential equations”
Hi. I am stuck in doing some homework, and I was hoping I could get some help.
The task is to analytically or numerically solve some differential equations. I will provide the full task for completeness:
These are the DE’s to solve, in the following task:
“Real valued” Rabi frequencies means that \Omega is simply some real number, which reduces the complexity quite a bit. Below is my attempt at defining this, using ModelingToolkit.jl:
using ModelingToolkit
using DifferentialEquations
@variables t c̃₁(t) c̃₂(t) # independent and dependent variables
@parameters Ω Δ # parameters
∂ₜ = Differential(t) # define an operator for the differentiation w.r.t. time
Inspired by the docs, I tried to define a vector of equations:
@named eqs = ODESystem([∂ₜ(c̃₁) ~ Ω*im*c̃₂*cis(t*Δ),
∂ₜ(c̃₂) ~ Ω*im*c̃₁*cis(-t*Δ)
])
Resulting in
ERROR: type Array has no field lhs
Stacktrace:
So instead, I tried what I found inntuitive - defining two equations, and giving those as a vector:
julia> @named eq1 = ODESystem(∂ₜ(c̃₁) ~ Ω*im*c̃₂*cis(t*Δ))
Model eq1 with 2 equations
States (2):
c̃₁(t)
c̃₂(t)
Parameters (2):
Ω
Δ
julia> @named eq2 = ODESystem(∂ₜ(c̃₂) ~ Ω*im*c̃₁*cis(-t*Δ))
Model eq2 with 2 equations
States (2):
c̃₂(t)
c̃₁(t)
Parameters (2):
Ω
Δ
So far so good I think. I do not get why both equations say “with 2 equations”.
I then attempt:
julia> using DifferentialEquations: solve
julia> initial_conds = [c̃₁ => 1.0, c̃₂ => 0.0];
julia> tspan = (0.0, 10.0);
julia> params = [Ω => 1.0, Δ => 1.0];
julia> prob = ODEProblem([eq1, eq2], initial_conds, tspan, params)
ERROR: No methods were found for the model function passed to the equation solver.
The function `f` needs to have dispatches, for example, for an ODEProblem
`f` must define either `f(u,p,t)` or `f(du,u,p,t)`. For more information
on how the model function `f` should be defined, consult the docstring for
the appropriate `AbstractSciMLFunction`.
Offending function: f
Stacktrace:
[1] isinplace(f::Vector{ODESystem}, inplace_param_number::Int64, fname::String, iip_preferred::Bool; has_two_dispatches::Bool, isoptimization::Bool)
@ SciMLBase ~/.julia/packages/SciMLBase/RAGXU/src/utils.jl:236
[2] isinplace (repeats 2 times)
@ ~/.julia/packages/SciMLBase/RAGXU/src/utils.jl:229 [inlined]
[3] ODEProblem(f::Vector{ODESystem}, u0::Vector{Pair{Num, Float64}}, tspan::Tuple{Float64, Float64}, p::Vector{Pair{Num, Float64}}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ SciMLBase ~/.julia/packages/SciMLBase/RAGXU/src/problems/ode_problems.jl:168
[4] ODEProblem(f::Vector{ODESystem}, u0::Vector{Pair{Num, Float64}}, tspan::Tuple{Float64, Float64}, p::Vector{Pair{Num, Float64}})
@ SciMLBase ~/.julia/packages/SciMLBase/RAGXU/src/problems/ode_problems.jl:167
[5] top-level scope
@ REPL[33]:1
Now I realize that I could be going about it the wrong way. Is it even an ODE system, or something else? I do however not know how to proceed, and would much appreciate some pointers.
Do anyone have the know-how and time to help me out?