Bug in VectorFieldPlot[] with InterpolatingFunction[]?












5












$begingroup$


While looking at How do I Plot a Divergence?, I thought to suggest the following as a solution to the OP's problem (where potdistr is an InterpolatingFunction solution to a PDE returned by NDSolve):



VectorDensityPlot[
Evaluate[Grad[potdistr[x, y], {x, y}]],
{x, -0.01, 0.11}, {y, -0.005, 0.053}]


I surprised that it worked once and then failed on subsequent calls. It seems to be connected to InterpolatingFunction and values being set for x and y. Here is a minimal example:



field = {Interpolation[Range[4]^2/4][y], x};
VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]


Subsequent calls generate a InterpolatingFunction::dmval extrapolation warning message and the vector field is constant.



The problem does not occur if field = {y^2/4, x} is used. It does not occur for VectorPlot, DensityPlot, ContourPlot, or Plot3D.



What's going on? Is it a bug? Is there a way to get it to work?



Additional info:



$Version
(* "11.3.0 for Mac OS X x86 (64-bit) (January 22, 2018)" *)


Filed as [CASE:4228039]










share|improve this question











$endgroup$












  • $begingroup$
    I was fiddling with the same problem, and had odd results when attempting to do a StreamPlot of the gradient of potexpr.
    $endgroup$
    – MikeY
    11 hours ago


















5












$begingroup$


While looking at How do I Plot a Divergence?, I thought to suggest the following as a solution to the OP's problem (where potdistr is an InterpolatingFunction solution to a PDE returned by NDSolve):



VectorDensityPlot[
Evaluate[Grad[potdistr[x, y], {x, y}]],
{x, -0.01, 0.11}, {y, -0.005, 0.053}]


I surprised that it worked once and then failed on subsequent calls. It seems to be connected to InterpolatingFunction and values being set for x and y. Here is a minimal example:



field = {Interpolation[Range[4]^2/4][y], x};
VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]


Subsequent calls generate a InterpolatingFunction::dmval extrapolation warning message and the vector field is constant.



The problem does not occur if field = {y^2/4, x} is used. It does not occur for VectorPlot, DensityPlot, ContourPlot, or Plot3D.



What's going on? Is it a bug? Is there a way to get it to work?



Additional info:



$Version
(* "11.3.0 for Mac OS X x86 (64-bit) (January 22, 2018)" *)


Filed as [CASE:4228039]










share|improve this question











$endgroup$












  • $begingroup$
    I was fiddling with the same problem, and had odd results when attempting to do a StreamPlot of the gradient of potexpr.
    $endgroup$
    – MikeY
    11 hours ago
















5












5








5





$begingroup$


While looking at How do I Plot a Divergence?, I thought to suggest the following as a solution to the OP's problem (where potdistr is an InterpolatingFunction solution to a PDE returned by NDSolve):



VectorDensityPlot[
Evaluate[Grad[potdistr[x, y], {x, y}]],
{x, -0.01, 0.11}, {y, -0.005, 0.053}]


I surprised that it worked once and then failed on subsequent calls. It seems to be connected to InterpolatingFunction and values being set for x and y. Here is a minimal example:



field = {Interpolation[Range[4]^2/4][y], x};
VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]


Subsequent calls generate a InterpolatingFunction::dmval extrapolation warning message and the vector field is constant.



The problem does not occur if field = {y^2/4, x} is used. It does not occur for VectorPlot, DensityPlot, ContourPlot, or Plot3D.



What's going on? Is it a bug? Is there a way to get it to work?



Additional info:



$Version
(* "11.3.0 for Mac OS X x86 (64-bit) (January 22, 2018)" *)


Filed as [CASE:4228039]










share|improve this question











$endgroup$




While looking at How do I Plot a Divergence?, I thought to suggest the following as a solution to the OP's problem (where potdistr is an InterpolatingFunction solution to a PDE returned by NDSolve):



VectorDensityPlot[
Evaluate[Grad[potdistr[x, y], {x, y}]],
{x, -0.01, 0.11}, {y, -0.005, 0.053}]


I surprised that it worked once and then failed on subsequent calls. It seems to be connected to InterpolatingFunction and values being set for x and y. Here is a minimal example:



field = {Interpolation[Range[4]^2/4][y], x};
VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]


Subsequent calls generate a InterpolatingFunction::dmval extrapolation warning message and the vector field is constant.



The problem does not occur if field = {y^2/4, x} is used. It does not occur for VectorPlot, DensityPlot, ContourPlot, or Plot3D.



What's going on? Is it a bug? Is there a way to get it to work?



Additional info:



$Version
(* "11.3.0 for Mac OS X x86 (64-bit) (January 22, 2018)" *)


Filed as [CASE:4228039]







plotting evaluation interpolation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 11 hours ago







Michael E2

















asked 12 hours ago









Michael E2Michael E2

148k12198475




148k12198475












  • $begingroup$
    I was fiddling with the same problem, and had odd results when attempting to do a StreamPlot of the gradient of potexpr.
    $endgroup$
    – MikeY
    11 hours ago




















  • $begingroup$
    I was fiddling with the same problem, and had odd results when attempting to do a StreamPlot of the gradient of potexpr.
    $endgroup$
    – MikeY
    11 hours ago


















$begingroup$
I was fiddling with the same problem, and had odd results when attempting to do a StreamPlot of the gradient of potexpr.
$endgroup$
– MikeY
11 hours ago






$begingroup$
I was fiddling with the same problem, and had odd results when attempting to do a StreamPlot of the gradient of potexpr.
$endgroup$
– MikeY
11 hours ago












2 Answers
2






active

oldest

votes


















5












$begingroup$

What is happening is that x and y are being set equal to numeric values. (One might notice that the color for x and y changes from blue to black, but my eyes have trouble seeing that for single-letter variables.) For some reason, these values are outside the domain specified in the plot. I think this must be a bug and have reported it to WRI.



Clear[x, y]
{x, y}
field = {Interpolation[Range[4]^2/4][y], x};
VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]
{x, y}


enter image description here



One possible workaround is to clear the variables after plotting with Clear[x, y]. Another is to use Block:



Block[{x, y}, VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]]


Further, it does not seem restricted only to InterpolatingFunction. The following has the same issue, and, further, VectorStyle is ignored:



Clear[x, y, ff]
{x, y}
ff[xx_, yy_] := {yy^2/4, xx};
VectorDensityPlot[ff[x, y], {x, 1, 4}, {y, 1, 4}, VectorStyle -> Red]
{x, y}
(* output is the same as above, same coloring *)


Pre-evaluating ff[x, y] gives the desired plot:



VectorDensityPlot[Evaluate@ff[x, y], {x, 1, 4}, {y, 1, 4}, VectorStyle -> Red]





share|improve this answer









$endgroup$





















    2












    $begingroup$

    This works...once you have potdistr, run this to get a Function



    pdg = Evaluate[Grad[potdistr[#1, #2], {#1, #2}]] &


    You can then run the plot function repeatedly, no problem, and go back and run previous statements (you couldn't when x, y were getting set).



    VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]
    VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]
    VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]


    enter image description here



    You can also run this kludgy version, but it is slow.



    VectorDensityPlot[Evaluate[Grad[potdistr[#1, #2], {#1, #2}]] &[x, y], 
    {x, 0, 0.1}, {y, 0, 0.05}]


    I was interested in the not very useful looking StreamPlot I was getting.



    StreamPlot[pdg[x, y], {x, 0, 0.1}, {y, 0, 0.05}]


    enter image description here



    One thing I found odd is that if you look at the domain for potdistr versus the plot ranges people are using, there should be some extrapolation going on. Shouldn't we get warnings for that?






    share|improve this answer









    $endgroup$













    • $begingroup$
      Can you explain why the first method works? It might be worth pointing out that VectorDensityPlot still sets x and y here, but this method gets around the trouble it causes in other methods.
      $endgroup$
      – Michael E2
      5 hours ago










    • $begingroup$
      Frankly I’m not sure of the details, but it seems a best practice to define functions this way anyway.
      $endgroup$
      – MikeY
      2 hours ago










    • $begingroup$
      On the one hand, it's because pdg does not depend on x or y. Instead, the gradient is computed by differentiating the function with respect to #1 and #2 (Slot[1] and Slot[2]) which are Protected. Mathematica allows this use of #1 and #2, which is convenient here. On the other hand, the x and y inside VectorDensityPlot[pdg[x, y],...] are effectively localized using Block. This means that any global values for x and y are temporarily cleared before the plot is calculated....
      $endgroup$
      – Michael E2
      1 hour ago










    • $begingroup$
      ....From these two reasons. your approach, while not preventing x and y from from being overwritten, solves the major problem of making the plot work. [Obviously, I knew the answer. I just thought the answer would be improved by an explanation, for others who are looking to understand Mathematica better. Since it's your answer, I was encouraging you to add such an explanation.]
      $endgroup$
      – Michael E2
      1 hour ago










    • $begingroup$
      I like your explanation better. :) It's not always clear to me how an InterpolatingFunction's are set.
      $endgroup$
      – MikeY
      1 hour ago











    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "387"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192118%2fbug-in-vectorfieldplot-with-interpolatingfunction%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5












    $begingroup$

    What is happening is that x and y are being set equal to numeric values. (One might notice that the color for x and y changes from blue to black, but my eyes have trouble seeing that for single-letter variables.) For some reason, these values are outside the domain specified in the plot. I think this must be a bug and have reported it to WRI.



    Clear[x, y]
    {x, y}
    field = {Interpolation[Range[4]^2/4][y], x};
    VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]
    {x, y}


    enter image description here



    One possible workaround is to clear the variables after plotting with Clear[x, y]. Another is to use Block:



    Block[{x, y}, VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]]


    Further, it does not seem restricted only to InterpolatingFunction. The following has the same issue, and, further, VectorStyle is ignored:



    Clear[x, y, ff]
    {x, y}
    ff[xx_, yy_] := {yy^2/4, xx};
    VectorDensityPlot[ff[x, y], {x, 1, 4}, {y, 1, 4}, VectorStyle -> Red]
    {x, y}
    (* output is the same as above, same coloring *)


    Pre-evaluating ff[x, y] gives the desired plot:



    VectorDensityPlot[Evaluate@ff[x, y], {x, 1, 4}, {y, 1, 4}, VectorStyle -> Red]





    share|improve this answer









    $endgroup$


















      5












      $begingroup$

      What is happening is that x and y are being set equal to numeric values. (One might notice that the color for x and y changes from blue to black, but my eyes have trouble seeing that for single-letter variables.) For some reason, these values are outside the domain specified in the plot. I think this must be a bug and have reported it to WRI.



      Clear[x, y]
      {x, y}
      field = {Interpolation[Range[4]^2/4][y], x};
      VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]
      {x, y}


      enter image description here



      One possible workaround is to clear the variables after plotting with Clear[x, y]. Another is to use Block:



      Block[{x, y}, VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]]


      Further, it does not seem restricted only to InterpolatingFunction. The following has the same issue, and, further, VectorStyle is ignored:



      Clear[x, y, ff]
      {x, y}
      ff[xx_, yy_] := {yy^2/4, xx};
      VectorDensityPlot[ff[x, y], {x, 1, 4}, {y, 1, 4}, VectorStyle -> Red]
      {x, y}
      (* output is the same as above, same coloring *)


      Pre-evaluating ff[x, y] gives the desired plot:



      VectorDensityPlot[Evaluate@ff[x, y], {x, 1, 4}, {y, 1, 4}, VectorStyle -> Red]





      share|improve this answer









      $endgroup$
















        5












        5








        5





        $begingroup$

        What is happening is that x and y are being set equal to numeric values. (One might notice that the color for x and y changes from blue to black, but my eyes have trouble seeing that for single-letter variables.) For some reason, these values are outside the domain specified in the plot. I think this must be a bug and have reported it to WRI.



        Clear[x, y]
        {x, y}
        field = {Interpolation[Range[4]^2/4][y], x};
        VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]
        {x, y}


        enter image description here



        One possible workaround is to clear the variables after plotting with Clear[x, y]. Another is to use Block:



        Block[{x, y}, VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]]


        Further, it does not seem restricted only to InterpolatingFunction. The following has the same issue, and, further, VectorStyle is ignored:



        Clear[x, y, ff]
        {x, y}
        ff[xx_, yy_] := {yy^2/4, xx};
        VectorDensityPlot[ff[x, y], {x, 1, 4}, {y, 1, 4}, VectorStyle -> Red]
        {x, y}
        (* output is the same as above, same coloring *)


        Pre-evaluating ff[x, y] gives the desired plot:



        VectorDensityPlot[Evaluate@ff[x, y], {x, 1, 4}, {y, 1, 4}, VectorStyle -> Red]





        share|improve this answer









        $endgroup$



        What is happening is that x and y are being set equal to numeric values. (One might notice that the color for x and y changes from blue to black, but my eyes have trouble seeing that for single-letter variables.) For some reason, these values are outside the domain specified in the plot. I think this must be a bug and have reported it to WRI.



        Clear[x, y]
        {x, y}
        field = {Interpolation[Range[4]^2/4][y], x};
        VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]
        {x, y}


        enter image description here



        One possible workaround is to clear the variables after plotting with Clear[x, y]. Another is to use Block:



        Block[{x, y}, VectorDensityPlot[field, {x, 1, 4}, {y, 1, 4}]]


        Further, it does not seem restricted only to InterpolatingFunction. The following has the same issue, and, further, VectorStyle is ignored:



        Clear[x, y, ff]
        {x, y}
        ff[xx_, yy_] := {yy^2/4, xx};
        VectorDensityPlot[ff[x, y], {x, 1, 4}, {y, 1, 4}, VectorStyle -> Red]
        {x, y}
        (* output is the same as above, same coloring *)


        Pre-evaluating ff[x, y] gives the desired plot:



        VectorDensityPlot[Evaluate@ff[x, y], {x, 1, 4}, {y, 1, 4}, VectorStyle -> Red]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 12 hours ago









        Michael E2Michael E2

        148k12198475




        148k12198475























            2












            $begingroup$

            This works...once you have potdistr, run this to get a Function



            pdg = Evaluate[Grad[potdistr[#1, #2], {#1, #2}]] &


            You can then run the plot function repeatedly, no problem, and go back and run previous statements (you couldn't when x, y were getting set).



            VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]
            VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]
            VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]


            enter image description here



            You can also run this kludgy version, but it is slow.



            VectorDensityPlot[Evaluate[Grad[potdistr[#1, #2], {#1, #2}]] &[x, y], 
            {x, 0, 0.1}, {y, 0, 0.05}]


            I was interested in the not very useful looking StreamPlot I was getting.



            StreamPlot[pdg[x, y], {x, 0, 0.1}, {y, 0, 0.05}]


            enter image description here



            One thing I found odd is that if you look at the domain for potdistr versus the plot ranges people are using, there should be some extrapolation going on. Shouldn't we get warnings for that?






            share|improve this answer









            $endgroup$













            • $begingroup$
              Can you explain why the first method works? It might be worth pointing out that VectorDensityPlot still sets x and y here, but this method gets around the trouble it causes in other methods.
              $endgroup$
              – Michael E2
              5 hours ago










            • $begingroup$
              Frankly I’m not sure of the details, but it seems a best practice to define functions this way anyway.
              $endgroup$
              – MikeY
              2 hours ago










            • $begingroup$
              On the one hand, it's because pdg does not depend on x or y. Instead, the gradient is computed by differentiating the function with respect to #1 and #2 (Slot[1] and Slot[2]) which are Protected. Mathematica allows this use of #1 and #2, which is convenient here. On the other hand, the x and y inside VectorDensityPlot[pdg[x, y],...] are effectively localized using Block. This means that any global values for x and y are temporarily cleared before the plot is calculated....
              $endgroup$
              – Michael E2
              1 hour ago










            • $begingroup$
              ....From these two reasons. your approach, while not preventing x and y from from being overwritten, solves the major problem of making the plot work. [Obviously, I knew the answer. I just thought the answer would be improved by an explanation, for others who are looking to understand Mathematica better. Since it's your answer, I was encouraging you to add such an explanation.]
              $endgroup$
              – Michael E2
              1 hour ago










            • $begingroup$
              I like your explanation better. :) It's not always clear to me how an InterpolatingFunction's are set.
              $endgroup$
              – MikeY
              1 hour ago
















            2












            $begingroup$

            This works...once you have potdistr, run this to get a Function



            pdg = Evaluate[Grad[potdistr[#1, #2], {#1, #2}]] &


            You can then run the plot function repeatedly, no problem, and go back and run previous statements (you couldn't when x, y were getting set).



            VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]
            VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]
            VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]


            enter image description here



            You can also run this kludgy version, but it is slow.



            VectorDensityPlot[Evaluate[Grad[potdistr[#1, #2], {#1, #2}]] &[x, y], 
            {x, 0, 0.1}, {y, 0, 0.05}]


            I was interested in the not very useful looking StreamPlot I was getting.



            StreamPlot[pdg[x, y], {x, 0, 0.1}, {y, 0, 0.05}]


            enter image description here



            One thing I found odd is that if you look at the domain for potdistr versus the plot ranges people are using, there should be some extrapolation going on. Shouldn't we get warnings for that?






            share|improve this answer









            $endgroup$













            • $begingroup$
              Can you explain why the first method works? It might be worth pointing out that VectorDensityPlot still sets x and y here, but this method gets around the trouble it causes in other methods.
              $endgroup$
              – Michael E2
              5 hours ago










            • $begingroup$
              Frankly I’m not sure of the details, but it seems a best practice to define functions this way anyway.
              $endgroup$
              – MikeY
              2 hours ago










            • $begingroup$
              On the one hand, it's because pdg does not depend on x or y. Instead, the gradient is computed by differentiating the function with respect to #1 and #2 (Slot[1] and Slot[2]) which are Protected. Mathematica allows this use of #1 and #2, which is convenient here. On the other hand, the x and y inside VectorDensityPlot[pdg[x, y],...] are effectively localized using Block. This means that any global values for x and y are temporarily cleared before the plot is calculated....
              $endgroup$
              – Michael E2
              1 hour ago










            • $begingroup$
              ....From these two reasons. your approach, while not preventing x and y from from being overwritten, solves the major problem of making the plot work. [Obviously, I knew the answer. I just thought the answer would be improved by an explanation, for others who are looking to understand Mathematica better. Since it's your answer, I was encouraging you to add such an explanation.]
              $endgroup$
              – Michael E2
              1 hour ago










            • $begingroup$
              I like your explanation better. :) It's not always clear to me how an InterpolatingFunction's are set.
              $endgroup$
              – MikeY
              1 hour ago














            2












            2








            2





            $begingroup$

            This works...once you have potdistr, run this to get a Function



            pdg = Evaluate[Grad[potdistr[#1, #2], {#1, #2}]] &


            You can then run the plot function repeatedly, no problem, and go back and run previous statements (you couldn't when x, y were getting set).



            VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]
            VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]
            VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]


            enter image description here



            You can also run this kludgy version, but it is slow.



            VectorDensityPlot[Evaluate[Grad[potdistr[#1, #2], {#1, #2}]] &[x, y], 
            {x, 0, 0.1}, {y, 0, 0.05}]


            I was interested in the not very useful looking StreamPlot I was getting.



            StreamPlot[pdg[x, y], {x, 0, 0.1}, {y, 0, 0.05}]


            enter image description here



            One thing I found odd is that if you look at the domain for potdistr versus the plot ranges people are using, there should be some extrapolation going on. Shouldn't we get warnings for that?






            share|improve this answer









            $endgroup$



            This works...once you have potdistr, run this to get a Function



            pdg = Evaluate[Grad[potdistr[#1, #2], {#1, #2}]] &


            You can then run the plot function repeatedly, no problem, and go back and run previous statements (you couldn't when x, y were getting set).



            VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]
            VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]
            VectorDensityPlot[pdg[x,y], {x, 0, 0.1}, {y, 0, 0.05}]


            enter image description here



            You can also run this kludgy version, but it is slow.



            VectorDensityPlot[Evaluate[Grad[potdistr[#1, #2], {#1, #2}]] &[x, y], 
            {x, 0, 0.1}, {y, 0, 0.05}]


            I was interested in the not very useful looking StreamPlot I was getting.



            StreamPlot[pdg[x, y], {x, 0, 0.1}, {y, 0, 0.05}]


            enter image description here



            One thing I found odd is that if you look at the domain for potdistr versus the plot ranges people are using, there should be some extrapolation going on. Shouldn't we get warnings for that?







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 6 hours ago









            MikeYMikeY

            3,032413




            3,032413












            • $begingroup$
              Can you explain why the first method works? It might be worth pointing out that VectorDensityPlot still sets x and y here, but this method gets around the trouble it causes in other methods.
              $endgroup$
              – Michael E2
              5 hours ago










            • $begingroup$
              Frankly I’m not sure of the details, but it seems a best practice to define functions this way anyway.
              $endgroup$
              – MikeY
              2 hours ago










            • $begingroup$
              On the one hand, it's because pdg does not depend on x or y. Instead, the gradient is computed by differentiating the function with respect to #1 and #2 (Slot[1] and Slot[2]) which are Protected. Mathematica allows this use of #1 and #2, which is convenient here. On the other hand, the x and y inside VectorDensityPlot[pdg[x, y],...] are effectively localized using Block. This means that any global values for x and y are temporarily cleared before the plot is calculated....
              $endgroup$
              – Michael E2
              1 hour ago










            • $begingroup$
              ....From these two reasons. your approach, while not preventing x and y from from being overwritten, solves the major problem of making the plot work. [Obviously, I knew the answer. I just thought the answer would be improved by an explanation, for others who are looking to understand Mathematica better. Since it's your answer, I was encouraging you to add such an explanation.]
              $endgroup$
              – Michael E2
              1 hour ago










            • $begingroup$
              I like your explanation better. :) It's not always clear to me how an InterpolatingFunction's are set.
              $endgroup$
              – MikeY
              1 hour ago


















            • $begingroup$
              Can you explain why the first method works? It might be worth pointing out that VectorDensityPlot still sets x and y here, but this method gets around the trouble it causes in other methods.
              $endgroup$
              – Michael E2
              5 hours ago










            • $begingroup$
              Frankly I’m not sure of the details, but it seems a best practice to define functions this way anyway.
              $endgroup$
              – MikeY
              2 hours ago










            • $begingroup$
              On the one hand, it's because pdg does not depend on x or y. Instead, the gradient is computed by differentiating the function with respect to #1 and #2 (Slot[1] and Slot[2]) which are Protected. Mathematica allows this use of #1 and #2, which is convenient here. On the other hand, the x and y inside VectorDensityPlot[pdg[x, y],...] are effectively localized using Block. This means that any global values for x and y are temporarily cleared before the plot is calculated....
              $endgroup$
              – Michael E2
              1 hour ago










            • $begingroup$
              ....From these two reasons. your approach, while not preventing x and y from from being overwritten, solves the major problem of making the plot work. [Obviously, I knew the answer. I just thought the answer would be improved by an explanation, for others who are looking to understand Mathematica better. Since it's your answer, I was encouraging you to add such an explanation.]
              $endgroup$
              – Michael E2
              1 hour ago










            • $begingroup$
              I like your explanation better. :) It's not always clear to me how an InterpolatingFunction's are set.
              $endgroup$
              – MikeY
              1 hour ago
















            $begingroup$
            Can you explain why the first method works? It might be worth pointing out that VectorDensityPlot still sets x and y here, but this method gets around the trouble it causes in other methods.
            $endgroup$
            – Michael E2
            5 hours ago




            $begingroup$
            Can you explain why the first method works? It might be worth pointing out that VectorDensityPlot still sets x and y here, but this method gets around the trouble it causes in other methods.
            $endgroup$
            – Michael E2
            5 hours ago












            $begingroup$
            Frankly I’m not sure of the details, but it seems a best practice to define functions this way anyway.
            $endgroup$
            – MikeY
            2 hours ago




            $begingroup$
            Frankly I’m not sure of the details, but it seems a best practice to define functions this way anyway.
            $endgroup$
            – MikeY
            2 hours ago












            $begingroup$
            On the one hand, it's because pdg does not depend on x or y. Instead, the gradient is computed by differentiating the function with respect to #1 and #2 (Slot[1] and Slot[2]) which are Protected. Mathematica allows this use of #1 and #2, which is convenient here. On the other hand, the x and y inside VectorDensityPlot[pdg[x, y],...] are effectively localized using Block. This means that any global values for x and y are temporarily cleared before the plot is calculated....
            $endgroup$
            – Michael E2
            1 hour ago




            $begingroup$
            On the one hand, it's because pdg does not depend on x or y. Instead, the gradient is computed by differentiating the function with respect to #1 and #2 (Slot[1] and Slot[2]) which are Protected. Mathematica allows this use of #1 and #2, which is convenient here. On the other hand, the x and y inside VectorDensityPlot[pdg[x, y],...] are effectively localized using Block. This means that any global values for x and y are temporarily cleared before the plot is calculated....
            $endgroup$
            – Michael E2
            1 hour ago












            $begingroup$
            ....From these two reasons. your approach, while not preventing x and y from from being overwritten, solves the major problem of making the plot work. [Obviously, I knew the answer. I just thought the answer would be improved by an explanation, for others who are looking to understand Mathematica better. Since it's your answer, I was encouraging you to add such an explanation.]
            $endgroup$
            – Michael E2
            1 hour ago




            $begingroup$
            ....From these two reasons. your approach, while not preventing x and y from from being overwritten, solves the major problem of making the plot work. [Obviously, I knew the answer. I just thought the answer would be improved by an explanation, for others who are looking to understand Mathematica better. Since it's your answer, I was encouraging you to add such an explanation.]
            $endgroup$
            – Michael E2
            1 hour ago












            $begingroup$
            I like your explanation better. :) It's not always clear to me how an InterpolatingFunction's are set.
            $endgroup$
            – MikeY
            1 hour ago




            $begingroup$
            I like your explanation better. :) It's not always clear to me how an InterpolatingFunction's are set.
            $endgroup$
            – MikeY
            1 hour ago


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192118%2fbug-in-vectorfieldplot-with-interpolatingfunction%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Loup dans la culture

            How to solve the problem of ntp “Unable to contact time server” from KDE?

            Connection limited (no internet access)