You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/src/tutorials/change_independent_variable.md
+9-8
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,10 @@ Ordinary differential equations describe the rate of change of some dependent va
4
4
For the modeler it is often most natural to write down the equations with a particular independent variable, say time $t$.
5
5
However, in many cases there are good reasons for changing the independent variable:
6
6
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).
10
11
11
12
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.
12
13
This is mechanical and error-prone.
@@ -34,9 +35,9 @@ It expresses the position $(x(t), y(t))$ as a function of time $t$.
34
35
But suppose we want to determine whether the projectile hits a target 10 meters away.
35
36
There are at least three ways of answering this:
36
37
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.
40
41
41
42
We will demonstrate the last method by changing the independent variable from $t$ to $x$.
42
43
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
55
56
56
57
The derivatives are now with respect to the new independent variable $x$, which can be accessed with `M2.x`.
57
58
58
-
!!! warn
59
+
!!! info
59
60
60
61
At this point `x`, `M1.x`, `M1s.x`, `M2.x`, `M2s.x` are *three* different variables.
61
62
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
66
67
67
68
```@example changeivar
68
69
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
0 commit comments