From 8d4ad7e718da1157d6c7978bb8c98098421dcc10 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Thu, 15 Aug 2024 14:41:47 +0200 Subject: [PATCH] tidy up some examples --- docs/src/examples/kinematic_loops.md | 23 ++++++++++++++++++++--- docs/src/examples/swing.md | 2 ++ docs/src/examples/wheel.md | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/src/examples/kinematic_loops.md b/docs/src/examples/kinematic_loops.md index 767e79f0..11e348f5 100644 --- a/docs/src/examples/kinematic_loops.md +++ b/docs/src/examples/kinematic_loops.md @@ -169,8 +169,8 @@ connections = [connect(j2.frame_b, b2.frame_a) @named fourbar_analytic = ODESystem(connections, t, systems = [world; systems]) fourbar_analytic = complete(fourbar_analytic) -ssys = structural_simplify(IRSystem(fourbar_analytic)) -prob = ODEProblem(ssys, [], (0.0, 1.4399)) +ssys_analytic = structural_simplify(IRSystem(fourbar_analytic)) +prob = ODEProblem(ssys_analytic, [], (0.0, 1.4399)) sol2 = solve(prob, FBDF(autodiff=true)) # about 4x faster than the simulation above plot!(sol2, idxs=[j2.s]) # Plot the same coordinate as above ``` @@ -182,4 +182,21 @@ Multibody.render(fourbar_analytic, sol2; x=-2, y = 2, z = 3, filename = "fourbar nothing # hide ``` -![animation](fourbar_analytic.gif) \ No newline at end of file +![animation](fourbar_analytic.gif) + +While the version with a cut joint were solving for +```@example kinloop +length(unknowns(ssys)) +``` +variables, the version with the joint assembly solved for only +```@example kinloop +length(unknowns(ssys_analytic)) +``` +variables. + +We can also inspect the mass matrices of the two systems to see how many nonlinear algebraic equations the solver has to deal with +```@example kinloop +using LinearAlgebra +diag(ssys.mass_matrix), diag(ssys_analytic.mass_matrix) +``` +A 1 on the diagonal indicates a differential equation, while a 0 indicates an algebraic equation. The cut-joint version has 6 nonlinear algebraic equations, while the joint assembly version has only 1. Both of them have 2 differential equations (position and velocity), corresponding to the 1 degree of freedom in the mechanism. Nonlinear algebraic equations are more expensive to solve than differential equations. \ No newline at end of file diff --git a/docs/src/examples/swing.md b/docs/src/examples/swing.md index a8663dc1..a6b39926 100644 --- a/docs/src/examples/swing.md +++ b/docs/src/examples/swing.md @@ -76,7 +76,9 @@ import GLMakie Multibody.render(model, sol; z = -5, filename = "simple_swing.gif") # Use "simple_swing.mp4" for a video file nothing # hide ``` + ![animation](simple_swing.gif) + This makes for a rather interesting-looking springy pendulum! diff --git a/docs/src/examples/wheel.md b/docs/src/examples/wheel.md index f37245cd..12c36c34 100644 --- a/docs/src/examples/wheel.md +++ b/docs/src/examples/wheel.md @@ -167,6 +167,7 @@ prob = ODEProblem(ssys, [], (0, 6)) sol = solve(prob, Tsit5()) render(model, sol, framerate=30, filename="car.gif", x=6, z=6, y=5) +nothing # hide ``` ![car animation](car.gif) \ No newline at end of file