2
$\begingroup$

I am trying to plot the gradient vector field over the contour plot of a function. While the demo function seems to work very well with the demo taken from How to use vector plot and gradient vectors? (first plot), I am getting a quite confusing vector plot with my own function (second plot). My gut feeling is that the vector should be orthogonal to the contours like the ones in the first plot.

Am I doing anything wrong here? I tried quitting the kernel and restart a new one to avoid any carry-over effects from my previous environment but no luck.

screenshot

\[Beta]=0.5; dH =1.5; dL =1; rL = 1;
g[\[Gamma]_,rH_]:=((dL (-1+\[Beta])-dH \[Beta]) (-dH (1+rL) (-1+\[Beta])+dL (1+rH) \[Beta] (1+rH \[Gamma])))/(dH dL (-1+rL (-1+\[Beta])-rH \[Beta]))
VectorPlot[Evaluate@Grad[g[\[Gamma],rH],{\[Gamma],rH}],{\[Gamma],0,1},{rH,1,5}];
Show[ContourPlot[g[\[Gamma],rH],{\[Gamma],0,1},{rH,1,5}],%]

It seems that it has something to do with the aspect ratio. If I specify the AspectRatio -> 5 in the contour plot, the vector field seems correct. I am able to get a sensible plot by manually multiplying the gradient in y axis by 10 (since specifying AspectRatio -> 5 actually gives you 1:10 visual aspect ratio).

I am still interested in what's behind the scene. It is a bug?

manual fix

$\endgroup$
  • 5
    $\begingroup$ Please post the code instead of just the image. $\endgroup$ – C. E. Aug 10 at 5:01
  • $\begingroup$ @C.E.Thanks for reminding. Added it in last edit. $\endgroup$ – John Smith Aug 10 at 18:49
  • 1
    $\begingroup$ What happens if you use AspectRatio -> Automatic or a domain whose side-lengths are equal? Orthogonality is not preserved if the axial directions are scaled by different magnitudes. $\endgroup$ – Michael E2 Aug 10 at 22:30
  • $\begingroup$ @MichaelE2 There is no problem when the side-lengths are equal. I think Mathematica gives the wrong vector plot when the side-lengths are scaled by different factors. The arrows are not pointing to the correct directions. $\endgroup$ – John Smith Aug 10 at 22:35
  • $\begingroup$ No, the problem is that when the scaling factors are different, angles are not preserved. It's not the fault of Mathematica. It's how geometry works. You have to use the same unit length on each axis to get an accurate picture of the angles. (Of course, it is possible that M has miscomputed the vectors, but I doubt it's likely.) $\endgroup$ – Michael E2 Aug 10 at 22:47
1
$\begingroup$

Per @MichaelE2 's answer,

The problem is that when the scaling factors are different, angles are not preserved. It's not the fault of Mathematica. It's how geometry works. You have to use the same unit length on each axis to get an accurate picture of the angles.

It is a misconception that the the vectors should be always orthogonal to the contours. However, "Orthogonality is not preserved if the axial directions are scaled by different magnitudes."

So Mathematica actually gives the right figure, and my manual adjustment was actually wrong!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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