Message Boards Message Boards

1
|
6250 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

StreamPlot the following gradient?

Posted 5 years ago

Hello, it could be, that plenty of people asked this question already. I didn't search the right way. Sorry!

My Problem is with very basic usage of Mathematica:

First I define my new Function:

myFunction[x_, y_] := x^2 - x^4

then I define the gradient of this function as a function:

myGradient[x_, y_] := Grad[myFunction[x, y], {x, y}]

When I want to StreamPlot[myGradient[x,y], {x, -2, 2}, {y, -2, 2}] I got an empty diagram. When I use the output of the second last command (myGradient...) the Plotting works fine (StreamPlot[%6, {x, -2, 2}, {y, -2, 2}]).

Why does it not work like this and how do I do it right? In general I want to use the output of some input as the value of a function.

Thanks!

POSTED BY: Julian SSS
3 Replies
Posted 5 years ago

Suppose StreamPlot starts by calculating what to display for x= -2 and y= -2.

So it calls myGradient[-2,-2]

Your definition of myGradient then starts to calculate Grad[myFunction[-2,-2],{-2,-2}]

You can probably see how that is going to be a problem.

You might try removing the : and thus changing your code to

myGradient[x_, y_] = Grad[myFunction[x, y], {x, y}]

That graph will display, but might look a little odd, changing your function to x^2 - y^4 might give a StreamPlot that looks more reasonable.

What the differences are between := and = and exactly why the evaluation does what it does in your example is a deeper issue. Understanding the depths of how evaluation works in Mathematica is key.

You also need to be aware of any cached prior definitions of functions which can sometimes change the behavior that you might be expecting. Those might be responsible for some of the problems you are seeing. You can quit the kernel or clear individual definitions or restart Mathematica to eliminate those.

POSTED BY: Bill Nelson
POSTED BY: Isaac Abraham
Anonymous User
Anonymous User
Posted 5 years ago

try this: EquationTrekker

EquationTrekker is one way to plot differential equations in Mathematica and not the easiest to find in Help (it's mentioned somewhere).

EquationTrekker has an interface for plotting (gradients) in the way it plots them.

https://reference.wolfram.com/language/EquationTrekker/tutorial/EquationTrekker.html

POSTED BY: Anonymous User
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract