Big coupled systems are nothing new. Sounds like you may have a differential-algebraic equation (DAE)? There are solvers for this too.
Using a coupled solver, e.g. a DAE solver, lets you focus on formulating the continuous-time equations, and let the solver handle discretizing into time steps (often at high order accuracy, often with adaptive sizes).
Hi @Mason, thanks for your solution! But in latest Julia, I found expv
has similar performance compared to exp
ā¦not sure whether I got the correct way to use itā¦but if I ran this:
using ExponentialUtilities
using BenchmarkTools
using StaticArrays
A = rand(4, 4)
As = SMatrix{4, 4}(A)
v = rand(4)
vs = SVector{4}(v)
t = 1e-3
# calculate exp(t * A) * v
@btime expv($t, $A, $v)
@btime expv($t, $As, $vs)
@btime exp($t*$As)*$vs
I got
2.989 μs (27 allocations: 2.22 KiB)
4-element Vector{Float64}:
0.6843916614773726
0.6584018736208126
0.9509576202197598
0.6793439922385884
213.225 ns (0 allocations: 0 bytes)
4-element SVector{4, Float64} with indices SOneTo(4):
0.6843916614773728
0.6584018736208129
0.9509576202197598
0.6793439922385885
213.211 ns (0 allocations: 0 bytes)
4-element SVector{4, Float64} with indices SOneTo(4):
0.6843916614773728
0.6584018736208129
0.9509576202197598
0.6793439922385885
Is that normal (compared the second and third ones)? I am using Julia with the version of 1.11.5