Mathematica - How to Graph Direction Fields of ODEs?

In summary, the guide on "Mathematica - How to Graph Direction Fields of ODEs" explains how to use Mathematica software to visualize direction fields for ordinary differential equations (ODEs). It covers the necessary commands and functions, such as `VectorPlot`, to create direction fields that illustrate the slope of solutions at various points in the plane. The tutorial includes step-by-step instructions, examples, and tips for customizing the graphs to enhance understanding of the behavior of solutions to ODEs.
  • #1
Ascendant0
154
33
So, I'm working on ODE at this point, and unfortunately I don't have the time to learn all of the Mathematica input for at least a few months. But, I was hoping someone could tell me how to graph direction fields of ODEs, either with the Mathematica input or free-form?

Looking through the Mathematica site, it looks like VectorPlot or VectorPlot3D is one of the two commands I'd be looking to use, but the two pages I found on the site show information that went over my head. I don't know how to enter in what I'm looking to do.

Basically, I want to be able to take something like y′+xy=x, and create a graph of the direction field within a given region. I wanted to take a little time to do this for multiple equations (including some of the ones I'm seeing in the OpenCourseWare lectures), so that I can get a better idea of the general type of field for certain types of ODEs (without having to take the time to put them together myself). Any help here would be greatly appreciated.
 
Physics news on Phys.org
  • #2
Ascendant0 said:
I don't know how to enter in what I'm looking to do.
Is this what you want?

1721206597868.png
 
  • Like
Likes Ascendant0
  • #3
renormalize said:
Is this what you want?

View attachment 348450
Yes, that's the type of thing I'm looking to do. How would I go about plugging a differential equation into a vector plot like that?
 
  • #4
Ascendant0 said:
Yes, that's the type of thing I'm looking to do. How would I go about plugging a differential equation into a vector plot like that?
Post #2 is the vector plot of the 1rst-order differential equation you gave: y′+xy=x.
 
  • Like
Likes Ascendant0
  • #5
renormalize said:
Post #2 is the vector plot of the 1rst-order differential equation you gave: y′+xy=x.
Oh, ok I got you. So it automatically assumes it as an equation for y' without having to plug it into the input. Thank you, I appreciate the help
 
  • #6
renormalize said:
Post #2 is the vector plot of the 1rst-order differential equation you gave: y′+xy=x.
I did have one other question in regards to that input. The "1" in front of the "x - xy", is that for "first order differential", or something else?
 
  • #7
Ascendant0 said:
I did have one other question in regards to that input. The "1" in front of the "x - xy", is that for "first order differential", or something else?
Do you understand the basic idea of plotting a "direction-" or a "slope-" field? Can you describe how you'd do it by hand with pencil and paper (before worrying about how it's done in a particular software like Mathematica)?
 
  • #8
renormalize said:
Do you understand the basic idea of plotting a "direction-" or a "slope-" field? Can you describe how you'd do it by hand with pencil and paper (before worrying about how it's done in a particular software like Mathematica)?
Yea, I have all that down. You plug in x, plug in y, then the answer gives you the slope at that location.

Like ##dy/dx = 2x^2 - 3y^3 ##; at x = 2 and y = 3, ##dy/dx = -73## (which is the slope)

If I didn't even know how to do that yet, it wouldn't be making much sense to be asking how to put it into Mathematica, lol.

But anyway, still not sure what the "1" in the front of the equation in VectorPlot means. What I do know is if I plug "y" in there instead of the 1, I get vectors in a circle. Looked around on the web, and I don't see anything from Mathematica that clarifies it for me.
 
  • #9
Ascendant0 said:
Yea, I have all that down. You plug in x, plug in y, then the answer gives you the slope at that location.

Like ##dy/dx = 2x^2 - 3y^3 ##; at x = 2 and y = 3, ##dy/dx = -73## (which is the slope)

If I didn't even know how to do that yet, it wouldn't be making much sense to be asking how to put it into Mathematica, lol.
You apparently don't understand because that's not the way to plot a direction-field. At each point ##x,y## you must to plot a vector, not a number like "##-73##". Please read https://en.wikipedia.org/wiki/Slope_field to learn how.
 
  • #10
renormalize said:
You apparently don't understand because that's not the way to plot a direction-field. At each point ##x,y## you must to plot a vector, not a number like "##-73##". Please read https://en.wikipedia.org/wiki/Slope_field to learn how.
How are you going to plot a direction field without knowing what the slope is at any given location? Did I say "draw a -73 there"? No, but without the slope, you most certainly aren't going to draw the direction field, which I'm well more than aware on how to draw. What I don't know is a specific part of the VectorPlot command above, and this is become completely tangential and irrelevant to what I'm trying to learn. I've plotted direction fields multiple times now by hand, just wasn't sure with VectorPlot, but I think I've figured it out between your previous help and testing various equations. I appreciate it.
 
  • Like
Likes renormalize

Similar threads

Replies
4
Views
747
Replies
1
Views
2K
Replies
3
Views
2K
Replies
3
Views
2K
Replies
1
Views
1K
Replies
3
Views
2K
Replies
4
Views
2K
Back
Top