Directions Fields

To plot a direction field, you will use the following syntax:

field1 : = plot::VectorField2d([1,differential]), x = start..end, y = start..end, Mesh = [Xarrow,Yarrow]):
plot(field1, GridVisible = TRUE)

This is nice, because in 2 lines of code, you can get a perfectly good direction field to your exact specifications. Now let's break it down:
  1. "field1 :=" defines our variable "field1" to our direction field expression
  2. "plot::VectorField2d" tells MuPad we want to generate a direction field plot
  3. "([1,differential]" MuPad automatically splits the differential into dx and dy functions, so for a normal function dy/dx, we can use the first space as a place-holder and the second as the differential expression. "differential" will be your expression.
  4. "x = start..end, y = start..end," In general, for MuPad to plot something, you need to give it a range of values to calculate to plot- basically you are determining the window size. "start" and "end" should be real numerical values.
  5. "Mesh = [Xarrow, Yarrow]):" This defines your arrow density. Although it may seem a bit extraneous, it can be very useful for making your graph look clean depending on what kind of function you are plotting. "Xarrow" and "Yarrow" should be positive integers. Don't forget to suppress output with a ":" at the end or you may get a confusing return response.
  6. "plot(field1, GridVisible = TRUE)" This actually plots the function. Recall that we defined "field1" as our graph, so we are calling on this variable. The GridVisible function just turns on a nice grid for your plot.
  7. Optional axis labels - In the "plot(field, ...)" command, you can add these functions separated by commas, and they will make your graph look fancy:
    1. AxesTitles = ["This is my Y axis Title" , "This is my X Axis Title"]
    2. Header = "This is the Official Name of My Graph"
For Example:
field := plot::VectorField2d([1, 3*sin(x+1+y)], x=0..6, y=0..6, Mesh=[25,25]):
plot(field, Header = "Charge Distribution", AxesTitles = ["Electron Densisty", "Time"], GridVisible = TRUE)

Finally, if you want to super-impose a solution line onto your plot, here is the next block of code:
f := (x, y) -> [(function)]:
solution1 := numeric::odesolve2(f, initialx, [initialy]):
curve1 := plot::Function2d(solution1(x)[1], x = start .. end, LineColor = RGB::Red):
plot(field, curve1, GridVisible = TRUE)

First we map F as a function. For "function" you need to place a [1] next to any "y" variable. For example [(x^2 + 2*y[1])]. Next we solve numerically using the odesolve2 function. "initialx" and "[initially]" should be your intial value such that f(initial) = initial(y). These should be real numbers. Next we define our curve as the plot of this solution, given a starting and ending point (usually the same start/end as before). I like to make the line color red so it pops out. Then, as before, we plot our field function as well as the curve function this time, on the same graph. Below is a full example.
field := plot::VectorField2d([1, 3*sin(x+1+y)], x=0..6, y=0..7, Mesh=[25,25]):
f := (x, y) -> [3*sin(x+1+y[1])]:
solution1 := numeric::odesolve2(f, 0, [5]):
curve1 := plot::Function2d(solution1(x)[1], x=0..6, LineColor = RGB::Red):
plot(field, curve1, Header = "Charge Distribution", AxesTitles = ["Electron Densisty", "Time"], GridVisible = TRUE)

Stability of Systems

The stability of certain solutions of a differential equation can be analyzed by looking at the direction field for the differential equation and imagining the trends of certain solutions. Solutions to differential equations come in 3 varieties: equilibrium, stable, and unstable. Equilibrium solutions satisfy the forcing term on the right hand side of the equation and are always perfectly horizontal - they remain constant as x gets greater. Stable solutions start above or below equilibrium solitions and tend toward the equilibrium solutions as x grows. Unstable solutions also start above or below equilibrium solutions, but they tend away from them as x grows. You can plot numeric solutions to your differential equation to illustrate this property, as in the example below:

Example of stable and unstable solutions.

Let us consider an autonomous equation

\[ \frac{{\text d}y}{{\text d}x} = y^2 -y -6 . \]

In this graph, we plot the equilibrium solutions in green, and the other solutions are in red. Notice that any solution corresponding with an initial value of less than 3 will be stable, but any solution corresponding to an initial value above 3 will blow up and result in an unstable solution.

field := plot::VectorField2d([1, y^2-y-6], x=0..5, y=-5..10, Mesh=[20,20]):

solution1 := numeric::odesolve2(f, 0, [3]):

solution2 := numeric::odesolve2(f, 0, [3.00001]):

solution3 := numeric::odesolve2(f, 0, [2.99]):

solution4 := numeric::odesolve2(f, 0, [-5]):

solution5 := numeric::odesolve2(f, 0, [-2]):

curve1 := plot::Function2d(solution1(x)[1], x=0..5, LineColor = RGB::Green):

curve2 := plot::Function2d(solution2(x)[1], x=0..5, LineColor = RGB::Red):

curve3 := plot::Function2d(solution3(x)[1], x=0..5, LineColor = RGB::Red):

curve4 := plot::Function2d(solution4(x)[1], x=0..5, LineColor = RGB::Red):

curve5 := plot::Function2d(solution5(x)[1], x=0..5, LineColor = RGB::Green):

plot(field, curve1, curve2, curve3, curve4, curve5, GridVisible = TRUE)

MuPAD graphics