Skip to main content
1-Visitor
October 1, 2013
Solved

Direction Field Plots (ODE's)

  • October 1, 2013
  • 1 reply
  • 7631 views

I've searched the forum, and all I can find are some old posts on the subject.

If I am given an Ordinary Differential Equation (ODE), and am told to plot the direction field, can I do so in Mathcad 14?

For example:

Graph a direction field. In the field, graph several solution curves, particularly those passing through the points (x,y)

y' = -2*x*y (0,.5), (0,1), (0,2)

Is this possible in Mathcad?

Best answer by Werner_E

Yes, I was just about to edit that post and attach the sheet but couldn't do so because you had already answered 😉

Here is the sheet. Please note that I have omitted the numbering of the x- and y-axis as this would not reflect the real x-/y-values as already described.

If you couldn't figure out how to do I may post a version using my 2D vector routine later.

EDIT: Changed the attached file; small error corrected

1 reply

25-Diamond I
October 1, 2013

Yes, you can do so called vector field plots in Mathcad 14 & 15 (not in Prime2). Look it up in the help.

But there are some limitations and drawbacks. These plots basically are 3D-plots and you would typically create a matrix of values and plot it. So the values at the ordinate and abscissa are not real x- and y-values but just the indices of your matrix elements.

1-Visitor
October 1, 2013

I looked at the help, and I honestly don't know where to start.

25-Diamond I
October 1, 2013

Its not as straightforward as one may like it to be. Mainly because its a 3D plot. So plotting the solution curves is not that intuitive either, but its possible. Maybe I find more time later to eleborate more on this.

For now a short starter. You can plot a vector field basically in two ways:

1) Plot two matrices, one would hold the x-component, the other the y-component of the vectors

2) Plot a single matrix consisting of complex numbers, the real part being the x-component, the imaginary part the y-component of the vectors.

vectorfield1.png

You have to notice a few things:

You have not much control about the position the vectors are plotted at. The position is defined by the matrix indices (and is affected by the value of ORIGIN). So assuming we stay with ORIGIN=1 you cannot have negative values here or non integers. So usually the scaling on the axis will not reflect the real x- and y-cvalues.

Also note that in the plot the row indices are horizontal and the column indices vertical from bottom upwards. So you may see it as the matrix turned for 90° counterclockwise.

The vectors are scaled so that the largest vector is of length 1.

So to create the necessary vector of slopes I usually find it easier to handle to use a matrix with complex numbers. The RHS of your ODE gives you a fine formula for the slope in each point so its not that difficult to obtain a matrix of slope values. You will then have to normalize those vectors later so all a drawn with equal length.

How do you intend to get the solution of the ODE? Using the numeric odesolve() or simply use the manual derived solution(s) C*e^(-x^2) ?

BTW, because of the drawbacks of Mathcads vertor field plot and also because this is a missing feature in Prime I developed some months ago a toolbox to be able to create vector field plots using a normal 2D-plot. You can find it here: http://communities.ptc.com/docs/DOC-3503 . I also had included as an example the slope field of an ODE along with some solution curves.