Direction Fields in Mathematica

Click For Summary
SUMMARY

This discussion focuses on plotting direction fields for differential equations using Mathematica, specifically the equation dv/dt = 32 - 8v. The user seeks clarification on the syntax of the PlotVectorField function, particularly the arguments {1, Last[eqn]} and the meaning of (xu) and (yu). A solution is provided, demonstrating how to use the PlotVectorField function effectively, along with additional code to overlay a solution on the vector field.

PREREQUISITES
  • Familiarity with differential equations and their graphical representations
  • Basic understanding of Mathematica syntax and functions
  • Knowledge of vector fields in mathematics
  • Experience with the Graphics`PlotField` package in Mathematica
NEXT STEPS
  • Explore the Mathematica documentation for the PlotVectorField function
  • Learn about the Graphics`PlotField` package in Mathematica
  • Study the implementation of NDSolve in Mathematica for solving differential equations
  • Investigate additional examples of direction fields and their applications in Mathematica
USEFUL FOR

This discussion is beneficial for students and educators in mathematics, particularly those working with differential equations, as well as Mathematica users seeking to enhance their graphical representation skills.

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 [tex]dv/dt = 32 - 8v[/tex]

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 9 ·
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K