How to plot space of bistable solutions?












2












$begingroup$


I have the following ODE system



dx1 = -0.7 x1 y2 
dy1 = 0.7 x1 y2 + 1.7 (1-x1-y1) y2 - y1
dx2 = -0.7 x2 y1
dy2 = 0.7 x2 y1 + 1.7 (1-x2-y2) y1 - y2


I have found that, for initial conditions of the type $x_1=1-y_1, x_2=1-y_2$, solutions either:




  • reach a steady-state where $y_1=y_2=0$

  • or reach a steady-state where $y_1,y_2>0$.


Now, I want to plot the plane of initial conditions $(y_1(0),y_2(0))$ and color each point in the plane blue or red depending on whether the steady-state falls in the first or second bucket.



I know how to use streamplot to explore the phase-space of solutions but I am not sure how to go about plotting the regions depending on the steady-state value. Any ideas would be much appreciated.










share|improve this question









$endgroup$












  • $begingroup$
    By the way, what's the system a model of?
    $endgroup$
    – Chris K
    4 hours ago






  • 1




    $begingroup$
    It's an extension of an epidemic model that exhibits bistability in the initial conditions. See this paper
    $endgroup$
    – rpa
    4 hours ago


















2












$begingroup$


I have the following ODE system



dx1 = -0.7 x1 y2 
dy1 = 0.7 x1 y2 + 1.7 (1-x1-y1) y2 - y1
dx2 = -0.7 x2 y1
dy2 = 0.7 x2 y1 + 1.7 (1-x2-y2) y1 - y2


I have found that, for initial conditions of the type $x_1=1-y_1, x_2=1-y_2$, solutions either:




  • reach a steady-state where $y_1=y_2=0$

  • or reach a steady-state where $y_1,y_2>0$.


Now, I want to plot the plane of initial conditions $(y_1(0),y_2(0))$ and color each point in the plane blue or red depending on whether the steady-state falls in the first or second bucket.



I know how to use streamplot to explore the phase-space of solutions but I am not sure how to go about plotting the regions depending on the steady-state value. Any ideas would be much appreciated.










share|improve this question









$endgroup$












  • $begingroup$
    By the way, what's the system a model of?
    $endgroup$
    – Chris K
    4 hours ago






  • 1




    $begingroup$
    It's an extension of an epidemic model that exhibits bistability in the initial conditions. See this paper
    $endgroup$
    – rpa
    4 hours ago
















2












2








2





$begingroup$


I have the following ODE system



dx1 = -0.7 x1 y2 
dy1 = 0.7 x1 y2 + 1.7 (1-x1-y1) y2 - y1
dx2 = -0.7 x2 y1
dy2 = 0.7 x2 y1 + 1.7 (1-x2-y2) y1 - y2


I have found that, for initial conditions of the type $x_1=1-y_1, x_2=1-y_2$, solutions either:




  • reach a steady-state where $y_1=y_2=0$

  • or reach a steady-state where $y_1,y_2>0$.


Now, I want to plot the plane of initial conditions $(y_1(0),y_2(0))$ and color each point in the plane blue or red depending on whether the steady-state falls in the first or second bucket.



I know how to use streamplot to explore the phase-space of solutions but I am not sure how to go about plotting the regions depending on the steady-state value. Any ideas would be much appreciated.










share|improve this question









$endgroup$




I have the following ODE system



dx1 = -0.7 x1 y2 
dy1 = 0.7 x1 y2 + 1.7 (1-x1-y1) y2 - y1
dx2 = -0.7 x2 y1
dy2 = 0.7 x2 y1 + 1.7 (1-x2-y2) y1 - y2


I have found that, for initial conditions of the type $x_1=1-y_1, x_2=1-y_2$, solutions either:




  • reach a steady-state where $y_1=y_2=0$

  • or reach a steady-state where $y_1,y_2>0$.


Now, I want to plot the plane of initial conditions $(y_1(0),y_2(0))$ and color each point in the plane blue or red depending on whether the steady-state falls in the first or second bucket.



I know how to use streamplot to explore the phase-space of solutions but I am not sure how to go about plotting the regions depending on the steady-state value. Any ideas would be much appreciated.







plotting differential-equations regions






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 6 hours ago









rparpa

506




506












  • $begingroup$
    By the way, what's the system a model of?
    $endgroup$
    – Chris K
    4 hours ago






  • 1




    $begingroup$
    It's an extension of an epidemic model that exhibits bistability in the initial conditions. See this paper
    $endgroup$
    – rpa
    4 hours ago




















  • $begingroup$
    By the way, what's the system a model of?
    $endgroup$
    – Chris K
    4 hours ago






  • 1




    $begingroup$
    It's an extension of an epidemic model that exhibits bistability in the initial conditions. See this paper
    $endgroup$
    – rpa
    4 hours ago


















$begingroup$
By the way, what's the system a model of?
$endgroup$
– Chris K
4 hours ago




$begingroup$
By the way, what's the system a model of?
$endgroup$
– Chris K
4 hours ago




1




1




$begingroup$
It's an extension of an epidemic model that exhibits bistability in the initial conditions. See this paper
$endgroup$
– rpa
4 hours ago






$begingroup$
It's an extension of an epidemic model that exhibits bistability in the initial conditions. See this paper
$endgroup$
– rpa
4 hours ago












2 Answers
2






active

oldest

votes


















3












$begingroup$

Here's an approach based on this answer by @ssch.



First, a function to solve the system and report the final values of y1[tmax] and y2[tmax]:



res[y10_?NumericQ, y20_?NumericQ] := Module[{sol},
sol = NDSolve[{
x1'[t] == -0.7 x1[t] y2[t],
y1'[t] == 0.7 x1[t] y2[t] + 1.7 (1 - x1[t] - y1[t]) y2[t] - y1[t],
x2'[t] == -0.7 x2[t] y1[t],
y2'[t] == 0.7 x2[t] y1[t] + 1.7 (1 - x2[t] - y2[t]) y1[t] - y2[t],
x1[0] == 1 - y10, y1[0] == y10, x2[0] == 1 - y20, y2[0] == y20},
{x1, y1, x2, y2}, {t, 0, tmax}][[1]];
Return[{y1[tmax], y2[tmax]} /. sol]
];


Then RegionPlot where the final values are close enough to {0, 0}:



tmax = 100;
tol = 10^-3;

RegionPlot[{Norm[res[y10, y20]] < tol, Norm[res[y10, y20]] > tol},
{y10, 0, 0.2}, {y20, 0, 0.2},
PlotPoints -> 20, MaxRecursion -> 2, PlotStyle -> {Blue, Red}, FrameLabel -> {y10, y20}]


Mathematica graphics



See also this question.






share|improve this answer









$endgroup$













  • $begingroup$
    Thanks!! I ended up figuring out another way and I posted my solution as the same time as yours. However, I'm accepting your answer as I think it's better!
    $endgroup$
    – rpa
    4 hours ago



















2












$begingroup$

Here's what I ended up doing in case anyone else has a similar question:



I used NDSolve to numerically solve the system. I then extracted the values of $y_1$ and $y_2$ at time $t=100$, which I know is sufficiently long for the system to reach steady-state. I then threshold the average of $y_1$ and $y_2$ and set the threshold close to zero. Then, I did this for multiple values of the initial conditions using Table and plotted the resulting array using arrayplot.



ArrayPlot[
Table[(i1[100] + i2[100])/2 /.
NDSolve[{s1'[t] == -0.7 s1[t] i2[t],
i1'[t] == 0.7 s1[t] i2[t] + 1.7 (1 - s1[t] - i1[t]) i2[t] - i1[t],
s2'[t] == -0.7 s2[t] i1[t],
i2'[t] == 0.7 s2[t] i1[t] + 1.7 (1 - s2[t] - i2[t]) i1[t] - i2[t],
i1[0] == p1, i2[0] == p2, s1[0] == 1 - p1, s2[0] == 1 - p2},
{i1, i2}, {t, 0, 100}][[1]], {p1, 0, 1, 0.005}, {p2, 0, 1, 0.005}],
ColorFunction -> (If[# > 0.02, Red, Blue] &), DataReversed -> True]


enter image description here






share|improve this answer









$endgroup$













    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%2f191772%2fhow-to-plot-space-of-bistable-solutions%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









    3












    $begingroup$

    Here's an approach based on this answer by @ssch.



    First, a function to solve the system and report the final values of y1[tmax] and y2[tmax]:



    res[y10_?NumericQ, y20_?NumericQ] := Module[{sol},
    sol = NDSolve[{
    x1'[t] == -0.7 x1[t] y2[t],
    y1'[t] == 0.7 x1[t] y2[t] + 1.7 (1 - x1[t] - y1[t]) y2[t] - y1[t],
    x2'[t] == -0.7 x2[t] y1[t],
    y2'[t] == 0.7 x2[t] y1[t] + 1.7 (1 - x2[t] - y2[t]) y1[t] - y2[t],
    x1[0] == 1 - y10, y1[0] == y10, x2[0] == 1 - y20, y2[0] == y20},
    {x1, y1, x2, y2}, {t, 0, tmax}][[1]];
    Return[{y1[tmax], y2[tmax]} /. sol]
    ];


    Then RegionPlot where the final values are close enough to {0, 0}:



    tmax = 100;
    tol = 10^-3;

    RegionPlot[{Norm[res[y10, y20]] < tol, Norm[res[y10, y20]] > tol},
    {y10, 0, 0.2}, {y20, 0, 0.2},
    PlotPoints -> 20, MaxRecursion -> 2, PlotStyle -> {Blue, Red}, FrameLabel -> {y10, y20}]


    Mathematica graphics



    See also this question.






    share|improve this answer









    $endgroup$













    • $begingroup$
      Thanks!! I ended up figuring out another way and I posted my solution as the same time as yours. However, I'm accepting your answer as I think it's better!
      $endgroup$
      – rpa
      4 hours ago
















    3












    $begingroup$

    Here's an approach based on this answer by @ssch.



    First, a function to solve the system and report the final values of y1[tmax] and y2[tmax]:



    res[y10_?NumericQ, y20_?NumericQ] := Module[{sol},
    sol = NDSolve[{
    x1'[t] == -0.7 x1[t] y2[t],
    y1'[t] == 0.7 x1[t] y2[t] + 1.7 (1 - x1[t] - y1[t]) y2[t] - y1[t],
    x2'[t] == -0.7 x2[t] y1[t],
    y2'[t] == 0.7 x2[t] y1[t] + 1.7 (1 - x2[t] - y2[t]) y1[t] - y2[t],
    x1[0] == 1 - y10, y1[0] == y10, x2[0] == 1 - y20, y2[0] == y20},
    {x1, y1, x2, y2}, {t, 0, tmax}][[1]];
    Return[{y1[tmax], y2[tmax]} /. sol]
    ];


    Then RegionPlot where the final values are close enough to {0, 0}:



    tmax = 100;
    tol = 10^-3;

    RegionPlot[{Norm[res[y10, y20]] < tol, Norm[res[y10, y20]] > tol},
    {y10, 0, 0.2}, {y20, 0, 0.2},
    PlotPoints -> 20, MaxRecursion -> 2, PlotStyle -> {Blue, Red}, FrameLabel -> {y10, y20}]


    Mathematica graphics



    See also this question.






    share|improve this answer









    $endgroup$













    • $begingroup$
      Thanks!! I ended up figuring out another way and I posted my solution as the same time as yours. However, I'm accepting your answer as I think it's better!
      $endgroup$
      – rpa
      4 hours ago














    3












    3








    3





    $begingroup$

    Here's an approach based on this answer by @ssch.



    First, a function to solve the system and report the final values of y1[tmax] and y2[tmax]:



    res[y10_?NumericQ, y20_?NumericQ] := Module[{sol},
    sol = NDSolve[{
    x1'[t] == -0.7 x1[t] y2[t],
    y1'[t] == 0.7 x1[t] y2[t] + 1.7 (1 - x1[t] - y1[t]) y2[t] - y1[t],
    x2'[t] == -0.7 x2[t] y1[t],
    y2'[t] == 0.7 x2[t] y1[t] + 1.7 (1 - x2[t] - y2[t]) y1[t] - y2[t],
    x1[0] == 1 - y10, y1[0] == y10, x2[0] == 1 - y20, y2[0] == y20},
    {x1, y1, x2, y2}, {t, 0, tmax}][[1]];
    Return[{y1[tmax], y2[tmax]} /. sol]
    ];


    Then RegionPlot where the final values are close enough to {0, 0}:



    tmax = 100;
    tol = 10^-3;

    RegionPlot[{Norm[res[y10, y20]] < tol, Norm[res[y10, y20]] > tol},
    {y10, 0, 0.2}, {y20, 0, 0.2},
    PlotPoints -> 20, MaxRecursion -> 2, PlotStyle -> {Blue, Red}, FrameLabel -> {y10, y20}]


    Mathematica graphics



    See also this question.






    share|improve this answer









    $endgroup$



    Here's an approach based on this answer by @ssch.



    First, a function to solve the system and report the final values of y1[tmax] and y2[tmax]:



    res[y10_?NumericQ, y20_?NumericQ] := Module[{sol},
    sol = NDSolve[{
    x1'[t] == -0.7 x1[t] y2[t],
    y1'[t] == 0.7 x1[t] y2[t] + 1.7 (1 - x1[t] - y1[t]) y2[t] - y1[t],
    x2'[t] == -0.7 x2[t] y1[t],
    y2'[t] == 0.7 x2[t] y1[t] + 1.7 (1 - x2[t] - y2[t]) y1[t] - y2[t],
    x1[0] == 1 - y10, y1[0] == y10, x2[0] == 1 - y20, y2[0] == y20},
    {x1, y1, x2, y2}, {t, 0, tmax}][[1]];
    Return[{y1[tmax], y2[tmax]} /. sol]
    ];


    Then RegionPlot where the final values are close enough to {0, 0}:



    tmax = 100;
    tol = 10^-3;

    RegionPlot[{Norm[res[y10, y20]] < tol, Norm[res[y10, y20]] > tol},
    {y10, 0, 0.2}, {y20, 0, 0.2},
    PlotPoints -> 20, MaxRecursion -> 2, PlotStyle -> {Blue, Red}, FrameLabel -> {y10, y20}]


    Mathematica graphics



    See also this question.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 4 hours ago









    Chris KChris K

    6,72421841




    6,72421841












    • $begingroup$
      Thanks!! I ended up figuring out another way and I posted my solution as the same time as yours. However, I'm accepting your answer as I think it's better!
      $endgroup$
      – rpa
      4 hours ago


















    • $begingroup$
      Thanks!! I ended up figuring out another way and I posted my solution as the same time as yours. However, I'm accepting your answer as I think it's better!
      $endgroup$
      – rpa
      4 hours ago
















    $begingroup$
    Thanks!! I ended up figuring out another way and I posted my solution as the same time as yours. However, I'm accepting your answer as I think it's better!
    $endgroup$
    – rpa
    4 hours ago




    $begingroup$
    Thanks!! I ended up figuring out another way and I posted my solution as the same time as yours. However, I'm accepting your answer as I think it's better!
    $endgroup$
    – rpa
    4 hours ago











    2












    $begingroup$

    Here's what I ended up doing in case anyone else has a similar question:



    I used NDSolve to numerically solve the system. I then extracted the values of $y_1$ and $y_2$ at time $t=100$, which I know is sufficiently long for the system to reach steady-state. I then threshold the average of $y_1$ and $y_2$ and set the threshold close to zero. Then, I did this for multiple values of the initial conditions using Table and plotted the resulting array using arrayplot.



    ArrayPlot[
    Table[(i1[100] + i2[100])/2 /.
    NDSolve[{s1'[t] == -0.7 s1[t] i2[t],
    i1'[t] == 0.7 s1[t] i2[t] + 1.7 (1 - s1[t] - i1[t]) i2[t] - i1[t],
    s2'[t] == -0.7 s2[t] i1[t],
    i2'[t] == 0.7 s2[t] i1[t] + 1.7 (1 - s2[t] - i2[t]) i1[t] - i2[t],
    i1[0] == p1, i2[0] == p2, s1[0] == 1 - p1, s2[0] == 1 - p2},
    {i1, i2}, {t, 0, 100}][[1]], {p1, 0, 1, 0.005}, {p2, 0, 1, 0.005}],
    ColorFunction -> (If[# > 0.02, Red, Blue] &), DataReversed -> True]


    enter image description here






    share|improve this answer









    $endgroup$


















      2












      $begingroup$

      Here's what I ended up doing in case anyone else has a similar question:



      I used NDSolve to numerically solve the system. I then extracted the values of $y_1$ and $y_2$ at time $t=100$, which I know is sufficiently long for the system to reach steady-state. I then threshold the average of $y_1$ and $y_2$ and set the threshold close to zero. Then, I did this for multiple values of the initial conditions using Table and plotted the resulting array using arrayplot.



      ArrayPlot[
      Table[(i1[100] + i2[100])/2 /.
      NDSolve[{s1'[t] == -0.7 s1[t] i2[t],
      i1'[t] == 0.7 s1[t] i2[t] + 1.7 (1 - s1[t] - i1[t]) i2[t] - i1[t],
      s2'[t] == -0.7 s2[t] i1[t],
      i2'[t] == 0.7 s2[t] i1[t] + 1.7 (1 - s2[t] - i2[t]) i1[t] - i2[t],
      i1[0] == p1, i2[0] == p2, s1[0] == 1 - p1, s2[0] == 1 - p2},
      {i1, i2}, {t, 0, 100}][[1]], {p1, 0, 1, 0.005}, {p2, 0, 1, 0.005}],
      ColorFunction -> (If[# > 0.02, Red, Blue] &), DataReversed -> True]


      enter image description here






      share|improve this answer









      $endgroup$
















        2












        2








        2





        $begingroup$

        Here's what I ended up doing in case anyone else has a similar question:



        I used NDSolve to numerically solve the system. I then extracted the values of $y_1$ and $y_2$ at time $t=100$, which I know is sufficiently long for the system to reach steady-state. I then threshold the average of $y_1$ and $y_2$ and set the threshold close to zero. Then, I did this for multiple values of the initial conditions using Table and plotted the resulting array using arrayplot.



        ArrayPlot[
        Table[(i1[100] + i2[100])/2 /.
        NDSolve[{s1'[t] == -0.7 s1[t] i2[t],
        i1'[t] == 0.7 s1[t] i2[t] + 1.7 (1 - s1[t] - i1[t]) i2[t] - i1[t],
        s2'[t] == -0.7 s2[t] i1[t],
        i2'[t] == 0.7 s2[t] i1[t] + 1.7 (1 - s2[t] - i2[t]) i1[t] - i2[t],
        i1[0] == p1, i2[0] == p2, s1[0] == 1 - p1, s2[0] == 1 - p2},
        {i1, i2}, {t, 0, 100}][[1]], {p1, 0, 1, 0.005}, {p2, 0, 1, 0.005}],
        ColorFunction -> (If[# > 0.02, Red, Blue] &), DataReversed -> True]


        enter image description here






        share|improve this answer









        $endgroup$



        Here's what I ended up doing in case anyone else has a similar question:



        I used NDSolve to numerically solve the system. I then extracted the values of $y_1$ and $y_2$ at time $t=100$, which I know is sufficiently long for the system to reach steady-state. I then threshold the average of $y_1$ and $y_2$ and set the threshold close to zero. Then, I did this for multiple values of the initial conditions using Table and plotted the resulting array using arrayplot.



        ArrayPlot[
        Table[(i1[100] + i2[100])/2 /.
        NDSolve[{s1'[t] == -0.7 s1[t] i2[t],
        i1'[t] == 0.7 s1[t] i2[t] + 1.7 (1 - s1[t] - i1[t]) i2[t] - i1[t],
        s2'[t] == -0.7 s2[t] i1[t],
        i2'[t] == 0.7 s2[t] i1[t] + 1.7 (1 - s2[t] - i2[t]) i1[t] - i2[t],
        i1[0] == p1, i2[0] == p2, s1[0] == 1 - p1, s2[0] == 1 - p2},
        {i1, i2}, {t, 0, 100}][[1]], {p1, 0, 1, 0.005}, {p2, 0, 1, 0.005}],
        ColorFunction -> (If[# > 0.02, Red, Blue] &), DataReversed -> True]


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 4 hours ago









        rparpa

        506




        506






























            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%2f191772%2fhow-to-plot-space-of-bistable-solutions%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

            Why is a white electrical wire connected to 2 black wires?

            Waikiki

            What are all the squawk codes?