Mathematica Direction Fields in Mathematica

AI Thread Summary
The discussion focuses on using Mathematica to plot a direction field for the differential equation dv/dt = 32 - 8v. The user expresses confusion regarding the syntax of the PlotVectorField function, particularly the arguments {1, Last[eqn]} and the meaning of (xu) and (yu) in the function format. A response clarifies that the first argument {1, Last[eqn]} represents the components of the vector field, where '1' corresponds to the t-component and Last[eqn] gives the right-hand side of the equation. The provided code example demonstrates how to load the necessary package and plot the direction field, including an additional code snippet to overlay a solution on the vector field. The importance of utilizing Mathematica's built-in documentation for learning is also emphasized.
steelphantom
Messages
158
Reaction score
0
I just picked up a copy of Mathematica through Penn State, and I'm trying to figure out how to plot a direction field of a differential equation. For example, I have the differential equation dv/dt = 32 - 8v

I've found http://support.wolfram.com/mathematica/graphics/2d/directionfield.html" on Wolfram's site that shows you how to do it, but in the line
Code:
In[3]:= field=PlotVectorField[{1,Last[eqn]},{x,-2,2},{y[x],-2,2}]
kind of confuses me with the arguments that are used. I understand the second two sets of arguments (x and y arguments), but what's up with the first one {1, Last[eqn]}? Where did the 1 and Last come from?

Also, there's another page on Wolfram's site that displays the following as the format for the PlotVectorField function:
Code:
PlotVectorField[f, {x, x0, x1, (xu)}, {y, y0, y1, (yu)}, (options)]
What do (xu) and (yu) represent? The rest of it I understand (I think! :redface: ). Sorry for all of these questions. I'm definitely a Mathematica n00b and I think it's going to take a little getting used to. Thanks!
 
Last edited by a moderator:
Physics news on Phys.org
First of all I suggest you always use the built in Mathematica documentation until you know lots and lots of what's in there.

The following code will do what you want:
Code:
(* Loads the Package *)

<< Graphics`PlotField`

(* The one is the t_component of the vector field and Last[
  Eqn] gives the right_hand_side of and equation i.e. the v_component. I put \
this in directly *)


Field = PlotVectorField[{1, 32 - 8v}, {t, 0, 10}, {v, -5, 5}]

(* Here is some more code that will impose a solutions on the vector field assuming that you also ran the code above*)

Show[Field, Plot[Evaluate[v[t] /. NDSolve[{v'[t] == 32 - 8v[t], v[0] == -6}, \
v, {t, 0, 20}]], {t, 0,
   10}, PlotStyle -> Red, PlotRange -> {{0, 10}, {-5, 5}}]]
 
Last edited:

Similar threads

Replies
3
Views
2K
Replies
3
Views
5K
Replies
1
Views
2K
Replies
2
Views
2K
Replies
3
Views
3K
Replies
5
Views
5K
Back
Top