|
| 1 | +# Vector Fields |
| 2 | + |
| 3 | +Vector fields can be plotted via the (unexported) |
| 4 | +[`MathematicalSystems.VectorField`](@ref) type. First we give an example where |
| 5 | +the vector field is represented by a function that takes a two-dimensional state |
| 6 | +vector and returns the corresponding two-dimensional (derivative) vector: |
| 7 | + |
| 8 | +```@example vector_fields |
| 9 | +using MathematicalSystems, Plots |
| 10 | +
|
| 11 | +f(x) = [2*x[2], -x[1]]; |
| 12 | +
|
| 13 | +V = MathematicalSystems.VectorField(f); |
| 14 | +
|
| 15 | +plot(V) |
| 16 | +``` |
| 17 | + |
| 18 | +Alternatively, one can also pass a continuous system: |
| 19 | + |
| 20 | +```@example vector_fields |
| 21 | +S = LinearContinuousSystem([0.0 2; -1 0]) |
| 22 | +
|
| 23 | +V = MathematicalSystems.VectorField(S); |
| 24 | +
|
| 25 | +plot(V) |
| 26 | +``` |
| 27 | + |
| 28 | +The above example shows the default grid of 20×20 points for the range |
| 29 | +``[-3, 3] × [-3, 3]``. A custom grid can be passed via the `grid_points` keyword |
| 30 | +argument, which takes a pair `(x, y)` whose entries specify ranges for the x and |
| 31 | +y coordinates of the grid points. For instance: |
| 32 | + |
| 33 | +```@example vector_fields |
| 34 | +xrange = range(-1, stop=3, length=5); |
| 35 | +
|
| 36 | +yrange = range(-5, stop=2, length=8); |
| 37 | +
|
| 38 | +plot(V; grid_points=(xrange, yrange)) |
| 39 | +``` |
| 40 | + |
| 41 | +The implementation supports projective plotting of vector fields with more than |
| 42 | +two output dimensions. For that, one can use the `dims` keyword argument to pass |
| 43 | +a vector with the two dimensions to plot: |
| 44 | + |
| 45 | +```@example vector_fields |
| 46 | +f(x) = [2*x[2], 42, -x[1]]; |
| 47 | +
|
| 48 | +V = MathematicalSystems.VectorField(f); |
| 49 | +
|
| 50 | +plot(V; dims=[1, 3]) |
| 51 | +``` |
0 commit comments