Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.6K Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Visualizing the gradient?

Posted 4 years ago

Hello,
To get a better understanding of the gradient, I would like to use the graphing powers of Mathematica.

In attempting to visualize the function, the vectors calculated using the gradient, and the calculated vector using the given starting point of (-2,3), I created the following notebook - see attached. However, this graphic representation in the notebook seems to have several problems. For example, the arrow representing the vector (starting at the given point of (-2,3) and ending at the calculated point of (-2,-2)) does not seem to be pointing in the direction of greatest increase, and is not a unit vector. When I normalized the calculated point of (-2,-2) I came up with the point (0,-1) which also changed the direction of the vector when plotted - which doesn't seem correct since it is my understanding that normalizing should only change the length of the vector and not the direction. Additionally, some of the vectors created using the VectorPlot[] function seems questionable.

At this point, I am sure it is something that is incorrect on my part, so please review my notebook and set me on the right path.

Thanks,

Attachments:
POSTED BY: Mitchell Sandlin
4 Replies

Thanks so much for your help, I certainly appreciate your comments and advice - they were of great use.

FYI - the arrow in my previous attached example is NOT pointing in the correct direction so it can be ignored. However, the large arrow has been an issue for some time and I was very glad to get it resolved.

Thanks Again,

Mitch Sandlin

POSTED BY: Mitchell Sandlin

Mitchell,

Your problem is that you are computing the slope at point {-2,3} as Q2 -- this is correct, however, when you plot Q2 you plot it as a point. It is a direction -- your plot must add P2 plus some multiple of Q2. The multiple determines the vector length. For example, use P2+Normalize[Q2].

Using your example:

Show[ContourPlot[f[x, y], {x, -5, 10}, {y, -5, 10}],
 Graphics[{{PointSize[Large], Black, 
    Point[{P2, P2 + Normalize[Q2]}]}}],
 Graphics[Arrow[{P2, P2 + Normalize[Q2]}]],
 VectorPlot[Evaluate[Grad[f[x, y], {x, y}]], {x, -5, 10}, {y, -5, 10},
   VectorPoints -> 8, AxesLabel -> Automatic]]
POSTED BY: Neil Singer

Hi Neil;

Thank you so much for your response, it answered my question exactly.

If I wanted to take the visualization up a notch and visualize the solution in both 2D and 3D, would the attached be a correct solution? Since I followed your example, I am pretty sure the 2D visualization is correct, but not real sure about the 3D visualization.

Thanks so much,

Mitch Sandlin

Attachments:
POSTED BY: Mitchell Sandlin

The 3D visualization has an arrowhead size problem.

Show[Plot3D[{f[x, y]}, {x, -5, 5}, {y, -8, 8}, PlotRange -> {-5, 5}, 
  AspectRatio -> 1, AxesLabel -> Automatic],
 Graphics3D[{PointSize[Large], Black, Point[{P, P + Normalize[Q]}]}],
 Graphics3D[{Arrowheads[0.02], Arrow[{P, P + Normalize[Q]}]}], 
 ImageSize -> Large]

I am not sure about the direction -- I did not check that. Are you trying to plot a normal to the surface?

Regards

Neil

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