-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrigid_body.jl
57 lines (44 loc) · 1.5 KB
/
rigid_body.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@doc raw"""
# Rigid body
```math
\begin{aligned}
\dot{x} = Ayz \\
\dot{y} = Bxz \\
\dot{z} = Cxy
\end{aligned},
```
where ``A = (I_2 - I_3)/(I_2I_3)``, ``B = (I_3 - I_1)/(I_3I_1)`` and ``C = (I_1 - I_2)/(I_1I_2)``; ``I_{\cdot}`` are the *principal components of inertia*.
The initial condition and the default parameters are taken from [bajars2023locally](@cite).
"""
module RigidBody
using GeometricEquations
using GeometricSolutions
using Parameters
export odeproblem, odeensemble
const tspan = (0.0, 100.0)
const tstep = 0.1
const default_parameters = (
I₁ = 2.,
I₂ = 1.,
I₃ = 2. / 3.
)
const q₀ = [cos(1.1), 0., sin(1.1)]
const q₁ = [cos(2.1), 0., sin(2.1)]
const q₂ = [cos(2.2), 0., sin(2.2)]
function rigid_body_v(v, t, q, params)
@unpack I₁, I₂, I₃ = params
A = (I₂ - I₃) / (I₂ * I₃)
B = (I₃ - I₁) / (I₃ * I₁)
C = (I₁ - I₂) / (I₁ * I₂)
v[1] = A * q[2] * q[3]
v[2] = B * q[1] * q[3]
v[3] = C * q[1] * q[2]
nothing
end
function odeproblem(q₀ = q₀; tspan = tspan, tstep = tstep, parameters = default_parameters)
ODEProblem(rigid_body_v, tspan, tstep, q₀; parameters = parameters)
end
function odeensemble(samples = [q₀, q₁, q₂]; parameters = default_parameters, tspan = tspan, tstep = tstep)
ODEEnsemble(rigid_body_v, tspan, tstep, samples; parameters = parameters)
end
end