1
$\begingroup$

I am a new Mathematica user, and I have run into a question. What is the difference between the output of the commands:

VectorPlot[{x, Sin[x - y]}, {x, -3, 3}, {y, -3, 3}]

and

VectorPlot[{1, Sin[x - y]}, {x, -3, 3}, {y, -3, 3}]

The only difference is the argument in the first braces, x and 1, but I am not sure what that means in terms of the vector field that is generated.

I understand this generates two vector fields. I did not understand how the input affects the generated output, i.e., what exactly does Mathematica require the entries here to be, and how does it interpret the difference in these two arguments for the VectorField command: {x, Sin[x - y]} and {1, Sin[x - y]}.

$\endgroup$
1
  • $\begingroup$ Is the nature of the question not clear -- and natural -- considering the context (read the tags!)? If it's not to you, you must not teach DEs very often. I don't see how my answer hasn't cleared up these concerns. $\endgroup$ Aug 9, 2014 at 0:54

1 Answer 1

3
$\begingroup$

Your post indicates that this is a question about differential equations, so I assume you are attempting to plot a slope field of some type for the DE $y'=sin(x-y)$. In that case, you will want to use the second of your two lines of code.

The functions VectorPlot, StreamPlot, etc. all expect vector input. The direction field / slope field / whatever at any given point $(x,y)$ should be a function of $x$ and $y$, and that direction is given as a vector. However, in a differential equation that is not the case. You are instead given $y'=sin(x-y)$ and no information about $x'$.

However, $x$ is your independent variable so $\frac{d}{dx}x=1$. That's why in the first coordinate, you have 1. In the second coordinate, you put whatever $y'$ is.

So whenever you have $y'=f(x,y)$, you would type:

f[x_,y_]= (*whatever*) ;
VectorPlot[{1,f[x,y]},{x,-3,3},{y,-3,3}]

You can change the bounds on the plot depending on what you want to see, of course.

Later, you will probably learn about systems of DEs, where you will have $x(t)$ and $y(t)$ both functions of $t$. In that case, you will be given $x'=f(x,y)$ and $y'=g(x,y)$, and there you would do:

f[x_,y_]= (*whatever*) ; 
g[x_,y_]= (*whatever*) ;
VectorPlot[{f[x,y],g[x,y]},{x,-3,3},{y,-3,3}]

However, what you have in the first example with {x,Sin[x-y]} would have to correspond to a system like $x'=x,\ y'=sin(x-y)$, which I doubt is what you have.

Hint: I'd recommend StreamPlot over VectorField if you are allowed to choose one or the other. For some systems the vector field can be confusing, and the stream plot is really what you want to see if it's a DE.

This is actually something I've discussed on my website here.

$\endgroup$
1
  • 1
    $\begingroup$ This answers my question exactly! Thank you for the very detailed explanation. I have taught DEs for a couple of years now, but never used Mathematica in the past, and I just didn't understand the input that it expects. Thanks for taking the time to give this response. $\endgroup$ Aug 10, 2014 at 1:41

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .