Skip to content

Commit 36447a9

Browse files
Merge pull request #3479 from hersle/change_ivar
Format tutorial
2 parents f690295 + 3f7397b commit 36447a9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

docs/src/tutorials/change_independent_variable.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ Ordinary differential equations describe the rate of change of some dependent va
44
For the modeler it is often most natural to write down the equations with a particular independent variable, say time $t$.
55
However, in many cases there are good reasons for changing the independent variable:
66

7-
1. One may want $y(x)$ as a function of $x$ instead of $(x(t), y(t))$ as a function of $t$
8-
2. Some differential equations vary more nicely (e.g. less stiff) with respect to one independent variable than another.
9-
3. It can reduce the number of equations that must be solved (e.g. $y(x)$ is one equation, while $(x(t), y(t))$ are two).
7+
1. One may want $y(x)$ as a function of $x$ instead of $(x(t), y(t))$ as a function of $t$
8+
9+
2. Some differential equations vary more nicely (e.g. less stiff) with respect to one independent variable than another.
10+
3. It can reduce the number of equations that must be solved (e.g. $y(x)$ is one equation, while $(x(t), y(t))$ are two).
1011

1112
To manually change the independent variable of an ODE, one must rewrite all equations in terms of a new variable and transform differentials with the chain rule.
1213
This is mechanical and error-prone.
@@ -34,9 +35,9 @@ It expresses the position $(x(t), y(t))$ as a function of time $t$.
3435
But suppose we want to determine whether the projectile hits a target 10 meters away.
3536
There are at least three ways of answering this:
3637

37-
- Solve the ODE for $(x(t), y(t))$ and use a callback to terminate when $x$ reaches 10 meters, and evaluate $y$ at the final time.
38-
- Solve the ODE for $(x(t), y(t))$ and use root finding to find the time when $x$ reaches 10 meters, and evaluate $y$ at that time.
39-
- Solve the ODE for $y(x)$ and evaluate it at 10 meters.
38+
- Solve the ODE for $(x(t), y(t))$ and use a callback to terminate when $x$ reaches 10 meters, and evaluate $y$ at the final time.
39+
- Solve the ODE for $(x(t), y(t))$ and use root finding to find the time when $x$ reaches 10 meters, and evaluate $y$ at that time.
40+
- Solve the ODE for $y(x)$ and evaluate it at 10 meters.
4041

4142
We will demonstrate the last method by changing the independent variable from $t$ to $x$.
4243
This transformation is well-defined for any non-zero horizontal velocity $v$, so $x$ and $t$ are one-to-one.
@@ -55,7 +56,7 @@ M2s # display this # hide
5556

5657
The derivatives are now with respect to the new independent variable $x$, which can be accessed with `M2.x`.
5758

58-
!!! warn
59+
!!! info
5960

6061
At this point `x`, `M1.x`, `M1s.x`, `M2.x`, `M2s.x` are *three* different variables.
6162
Meanwhile `y`, `M1.y`, `M1s.y`, `M2.y` and `M2s.y` are *four* different variables.
@@ -66,7 +67,7 @@ It is straightforward to evolve the ODE for 10 meters and plot the resulting tra
6667

6768
```@example changeivar
6869
using OrdinaryDiffEq, Plots
69-
prob = ODEProblem(M2s, [M2s.y => 0.0], [0.0, 10.0], [v => 8.0]) # throw 10 meters with x-velocity 8 m/s
70+
prob = ODEProblem(M2s, [M2s.y => 0.0], [0.0, 10.0], [v => 8.0]) # throw 10 meters
7071
sol = solve(prob, Tsit5())
7172
plot(sol; idxs = M2.y) # must index by M2.y = y(x); not M1.y = y(t)!
7273
```

0 commit comments

Comments
 (0)