Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Im trying to find the maximum of my gradient vector G[x,y], I've tried several options including FindMaximumValue, FindMaximum etc. but i couldn't find it.

The full function is shown below, any help would be greatly appreciated

G[x_,y_]:= {-5.4 E^(-2.25 ((-4 + x)^2 + (-2.5 + y)^2)) (-4 + x) - 
  6.4 E^(-4 ((-3.5 + x)^2 + (-1.5 + y)^2)) (-3.5 + x) - 
  8 E^(-4 ((-3 + x)^2 + (-3.5 + y)^2)) (-3 + x) - 
  9. E^(-9 ((-2.5 + x)^2 + (-1.5 + y)^2)) (-2.5 + x) - 
  5.5125 E^(-3.0625 ((-2 + x)^2 + (-3 + y)^2)) (-2 + x) - 
  1.8 E^(-(-1 + x)^2 - (-1 + y)^2) (-1 + x) - 
  30. E^(-25 ((-0.75 + x)^2 + (-2 + y)^2)) (-0.75 + 
     x), -8 E^(-4 ((-3 + x)^2 + (-3.5 + y)^2)) (-3.5 + y) - 
  5.5125 E^(-3.0625 ((-2 + x)^2 + (-3 + y)^2)) (-3 + y) - 
  5.4 E^(-2.25 ((-4 + x)^2 + (-2.5 + y)^2)) (-2.5 + y) - 
  30. E^(-25 ((-0.75 + x)^2 + (-2 + y)^2)) (-2 + y) - 
  6.4 E^(-4 ((-3.5 + x)^2 + (-1.5 + y)^2)) (-1.5 + y) - 
  9. E^(-9 ((-2.5 + x)^2 + (-1.5 + y)^2)) (-1.5 + y) - 
  1.8 E^(-(-1 + x)^2 - (-1 + y)^2) (-1 + y)}
share|improve this question
    
G[x,y] is not scales quantity. What do you mean by maximum of gradient vector? –  Algohi Jul 6 at 5:57
    
If you plot Plot3D[G[x, y], {x, 0, 5}, {y, 0, 5}] you get a bunch of lumps, i want to find the "peaks" –  Lebouski Jul 6 at 6:17
3  
note that, Plot3D[G[x, y], {x, 0, 5}, {y, 0, 5}] is actually a 3D plot if two functions. you can see it clearly from the plot. in this case you can find the max of each function separately, Maximize[G[x, y][[1]], {x, y}], Maximize[G[x, y][[2]], {x, y}]. –  Algohi Jul 6 at 6:28

1 Answer 1

I hope this is helpful (if I interpret your aim correctly): This is a little more challenging for your particular function.

g[x_, y_] := {-5.4 E^(-2.25 ((-4 + x)^2 + (-2.5 + y)^2)) (-4 + x) - 
   6.4 E^(-4 ((-3.5 + x)^2 + (-1.5 + y)^2)) (-3.5 + x) - 
   8 E^(-4 ((-3 + x)^2 + (-3.5 + y)^2)) (-3 + x) - 
   9. E^(-9 ((-2.5 + x)^2 + (-1.5 + y)^2)) (-2.5 + x) - 
   5.5125 E^(-3.0625 ((-2 + x)^2 + (-3 + y)^2)) (-2 + x) - 
   1.8 E^(-(-1 + x)^2 - (-1 + y)^2) (-1 + x) - 
   30. E^(-25 ((-0.75 + x)^2 + (-2 + y)^2)) (-0.75 + 
      x), -8 E^(-4 ((-3 + x)^2 + (-3.5 + y)^2)) (-3.5 + y) - 
   5.5125 E^(-3.0625 ((-2 + x)^2 + (-3 + y)^2)) (-3 + y) - 
   5.4 E^(-2.25 ((-4 + x)^2 + (-2.5 + y)^2)) (-2.5 + y) - 
   30. E^(-25 ((-0.75 + x)^2 + (-2 + y)^2)) (-2 + y) - 
   6.4 E^(-4 ((-3.5 + x)^2 + (-1.5 + y)^2)) (-1.5 + y) - 
   9. E^(-9 ((-2.5 + x)^2 + (-1.5 + y)^2)) (-1.5 + y) - 
   1.8 E^(-(-1 + x)^2 - (-1 + y)^2) (-1 + y)}

For simplicity maximizing $g(x,y).g(x,y)$ yields:

ma = Maximize[g[x, y].g[x, y], {x, y}]

yields: {0.595965, {x -> 1.1506, y -> 0.309118}}

However, you function has a lot of local maxima and minima. After looking at plot and choosing region of interest:

nma = NMaximize[{g[x, y].g[x, y], 0 < x < 1 && 0 < y < 2}, {x, y}]

yields: {8.14402, {x -> 0.607423, y -> 2.}}

Showing this interactively (the red mesh lines intersect at the first maximum and the green at the second):

gr = Manipulate[
  Plot3D[g[x, y].g[x, y], {x, -1, 4}, {y, -1, 4}, PlotRange -> {0, r},
    MeshFunctions -> {#1 &, #2 &, #1 &, #2 &}, 
   Mesh -> {{ma[[2, 1, 2]]}, {ma[[2, 2, 2]]}, {nma[[2, 1, 
        2]]}, {nma[[2, 2, 2]]}}, 
   MeshStyle -> {Red, Red, Green, Green}], {r, 1, 9}]

enter image description here

You can also visualize working backwards. A function whose gradient field is $g(x,y)$:

exp = (f[x, y] /. 
    First[DSolve[Thread[{D[f[x, y], x], D[f[x, y], y]} == g[x, y]], 
      f[x, y], {x, y}]]) /. C[1] -> 0;

Plotting candidate maximal gradients:

enter image description here

Or perhaps more instructively with ContourPlot and StreamPlot (reassuringly exp is consistent with gradient):

pt = Point[{x, y} /. ma[[2]]]
ptn = Point[{x, y} /. nma[[2]]]
cp = ContourPlot[exp, {x, -1, 5}, {y, -1, 5}];
sp = StreamPlot[g[x, y], {x, -1, 5}, {y, -1, 5}];
Show[cp, sp, 
 Graphics[{{PointSize[0.02], Red, pt}, {PointSize[0.02], Green, 
    ptn}}]]

enter image description here

share|improve this answer
    
Nice answer. Any reason why the contour plot is over $[-1,5]\times[-1,5]$ while the streamline plot is only over $[-1,4]\times[-1,4]$? –  Rahul Narain Jul 6 at 18:52
    
@RahulNarain...tiredness...sorry...flat outside the mountains and fiddled to get them on....does not change the interpretation but will check when I get time –  ubpdqn Jul 6 at 22:40
    
@RahulNarain have edited... –  ubpdqn Jul 7 at 7:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.