Skip to content

Commit 942362d

Browse files
Minor change, add plots
1 parent 7062937 commit 942362d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

docs/src/tutorials/spring_mass.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ sol = solve(prob, Rosenbrock23())
5555
plot(sol)
5656
```
5757

58+
![plotsol](https://user-images.githubusercontent.com/23384717/130322185-52ff1523-4ad8-4b24-94d3-3aa2c4a87082.png)
59+
5860
## Explanation
5961
### Building the components
6062
For each component we use a Julia function that returns an `ODESystem`. At the top, we define the fundamental properties of a `Mass`: it has a mass `m`, a position `pos` and a velocity `v`. We also define that the velocity is the rate of change of position with respect to time.
@@ -90,7 +92,7 @@ function Spring(; name, k = 1e4, l = 1.)
9092
end
9193
```
9294

93-
We now define functions that help construct the equations for a mass-spring system. First, the `connect_spring` function connects a `spring` between two positions `a` and `b`. Note that `a` and `b` can be the `pos` of a `Mass`, or just a fixed position such as `[0., 0.]`.
95+
We now define functions that help construct the equations for a mass-spring system. First, the `connect_spring` function connects a `spring` between two positions `a` and `b`. Note that `a` and `b` can be the `pos` of a `Mass`, or just a fixed position such as `[0., 0.]`. In that sense, the length of the spring `x` is given by the length of the vector `dir` joining `a` and `b`.
9496

9597
```julia
9698
function connect_spring(spring, a, b)
@@ -216,14 +218,16 @@ observed(sys)
216218

217219
These are explicit algebraic equations which can be used to reconstruct the required variables on the fly. This leads to dramatic computational savings since implicitly solving an ODE scales as O(n^3), so fewer states are signficantly better!
218220

219-
We can access these variables using the solution object. For example, let's retrieve the length of the spring over time:
221+
We can access these variables using the solution object. For example, let's retrieve the x-position of the mass over time:
220222

221223
```julia
222-
sol[spring.x]
224+
sol[mass.pos[1]]
223225
```
224226

225-
We can also plot its timeseries:
227+
We can also plot the path of the mass:
226228

227229
```julia
228-
plot(sol, vars = [spring.x])
229-
```
230+
plot(sol, vars = (mass.pos[1], mass.pos[2]))
231+
```
232+
233+
![plotpos](https://user-images.githubusercontent.com/23384717/130322197-cff35eb7-0739-471d-a3d9-af83d87f1cc7.png)

0 commit comments

Comments
 (0)