Differential Equation direction plot with pgfplots












36















In earlier thread Jake provided some code whom successfully draws the following differential equations in the range [0; 1]



dy/dx=2*x
dy/dx=x*sqrt(x)


See: How to draw slope fields with all the possible solution curves in latex



I have not been able to determine how to change the range to [-1; 1] for both dimensions. My attempt



xmin=-1.1, xmax=1.1, % Axis limits
ymin=-1.1, ymax=1.1,
domain=-1:1, y domain=-1:1,


Also, I had some trouble with the notation for a differential equation that consists of y, example (dy/dx=x^2+y^2-1).



My attempt:



declare function={f(x) = x^2 + f(x)^2 - 1;}









share|improve this question





























    36















    In earlier thread Jake provided some code whom successfully draws the following differential equations in the range [0; 1]



    dy/dx=2*x
    dy/dx=x*sqrt(x)


    See: How to draw slope fields with all the possible solution curves in latex



    I have not been able to determine how to change the range to [-1; 1] for both dimensions. My attempt



    xmin=-1.1, xmax=1.1, % Axis limits
    ymin=-1.1, ymax=1.1,
    domain=-1:1, y domain=-1:1,


    Also, I had some trouble with the notation for a differential equation that consists of y, example (dy/dx=x^2+y^2-1).



    My attempt:



    declare function={f(x) = x^2 + f(x)^2 - 1;}









    share|improve this question



























      36












      36








      36


      28






      In earlier thread Jake provided some code whom successfully draws the following differential equations in the range [0; 1]



      dy/dx=2*x
      dy/dx=x*sqrt(x)


      See: How to draw slope fields with all the possible solution curves in latex



      I have not been able to determine how to change the range to [-1; 1] for both dimensions. My attempt



      xmin=-1.1, xmax=1.1, % Axis limits
      ymin=-1.1, ymax=1.1,
      domain=-1:1, y domain=-1:1,


      Also, I had some trouble with the notation for a differential equation that consists of y, example (dy/dx=x^2+y^2-1).



      My attempt:



      declare function={f(x) = x^2 + f(x)^2 - 1;}









      share|improve this question
















      In earlier thread Jake provided some code whom successfully draws the following differential equations in the range [0; 1]



      dy/dx=2*x
      dy/dx=x*sqrt(x)


      See: How to draw slope fields with all the possible solution curves in latex



      I have not been able to determine how to change the range to [-1; 1] for both dimensions. My attempt



      xmin=-1.1, xmax=1.1, % Axis limits
      ymin=-1.1, ymax=1.1,
      domain=-1:1, y domain=-1:1,


      Also, I had some trouble with the notation for a differential equation that consists of y, example (dy/dx=x^2+y^2-1).



      My attempt:



      declare function={f(x) = x^2 + f(x)^2 - 1;}






      pgfplots asymptote






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 28 '17 at 12:39









      g.kov

      17.2k13976




      17.2k13976










      asked Oct 16 '13 at 11:05









      Alexander MathiasenAlexander Mathiasen

      18134




      18134






















          4 Answers
          4






          active

          oldest

          votes


















          32














          Using PGFPlotstable, you can use a naive numerical integration scheme to find the function directly within LaTeX:





          documentclass{article}
          usepackage{pgfplots, pgfplotstable}
          pgfplotsset{compat=1.8}

          usepackage{amsmath}

          pgfplotstableset{
          create on use/x/.style={
          create col/expr={
          pgfplotstablerow/201*2-1
          }
          },
          create on use/y/.style={
          create col/expr accum={
          pgfmathaccuma+(2/201)*(abs(pgfmathaccuma^2)+abs(thisrow{x}^2)-1)
          }{0.6}
          }
          }


          pgfplotstablenew{201}loadedtable

          begin{document}
          begin{tikzpicture}
          begin{axis}[
          view={0}{90},
          domain=-1:1,
          y domain=-1:1,
          xmax=1, ymax=1,
          samples=21
          ]
          addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
          addplot [thick, red] table [x=x, y=y] {loadedtable};
          end{axis}
          end{tikzpicture}

          end{document}





          share|improve this answer


























          • How to you change the x and y values for the viewing window?

            – MaoYiyi
            Oct 17 '13 at 13:00



















          30














          (Sets of) ordinary differential equations (ODE) can be numerically solved using pstODEsolve from the pst-ode Plain-TeX / LaTeX package.



          Integration of the ODEs is done using the Runge-Kutta-Fehlberg method of 4th order with adaptive step size control (RKF45) during the ps2pdf conversion step.



          For plotting packages other than PSTricks, such as pgfplots to be used here, LaTeX must be run twice. The first run, must go the dvips+ps2pdf route, in order to write the solution table into a text file, which is then read and transformed into a chart by your favourite plotting package and TeX engine.



          The first compilation is done like this (option -dNOSAFER is necessary to allow Ghostscript to write files):



          latex myfile
          dvips myfile
          ps2pdf -dNOSAFER myfile.ps


          The second run can involve your preferred toolchain pdflatex, xelatex, latex/dvips/ps2pdf, whatever. It plots the results using pgfplots.



          Alternatively, a single call to your favourite LaTeX engine with option --shell-escape is sufficient if the second code box below is used. (Under the hood, the chain of commands tex, dvips, ps2pdf -dNOSAFER is executed before the document is actually typeset.) Solution provided by Herbert.



          enter image description here



          documentclass{article}
          usepackage{amsmath}
          usepackage{pgfplots}
          pgfplotsset{compat=1.8}

          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
          usepackage{ifpdf}
          ifpdf
          IfFileExists{y0=-0.5.dat}{}{
          GenericError{}{MessageBreak%
          ===================================MessageBreak
          First, you have to runMessageBreakMessageBreak
          latex jobnameMessageBreak
          dvips jobnameMessageBreak
          ps2pdf -dNOSAFER jobname.psMessageBreakMessageBreak
          to solve the differential equation.MessageBreak
          ===================================}{}{}
          }
          else
          usepackage{pst-ode}

          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
          %solve dy/dx=x^2 + y^2 - 1 numerically for different initial values of y in the
          %interval x=[-1.1,1.1]; write resulting curves as tables with 100 output points
          %into text files
          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

          %y0=-0.5 --> y0=-0.5.dat
          pstODEsolve[algebraicOutputFormat,algebraic,saveData]{%
          y0=-0.5% %name of the output file `y0=-0.5.dat'
          }{
          t | x[0] %table format in `y0=-0.5.dat': x y
          }{
          -1.1 %integration domain x_min=-1.1
          }{
          1.1 %integration domain x_max=1.1
          }{
          100 %number of output points
          }{
          -0.5 %initial value y0(x_min)
          }{
          t^2+x[0]^2-1 % right hand side of ODE, note the special notation: x --> t, y --> x[0]
          }

          %y0=0.0 --> y0=0.0.dat
          pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.0}{t | x[0]}{-1.1}{1.1}{100}{0.0}{t^2+x[0]^2-1}

          %y0=0.5 --> y0=0.5.dat
          pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.5}{t | x[0]}{-1.1}{1.1}{100}{0.5}{t^2+x[0]^2-1}
          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
          fi

          begin{document}
          IfFileExists{y0=-0.5.dat}{}{dummy textend{document}}

          begin{tikzpicture}
          begin{axis}[
          axis equal image, % Unit vectors for both axes have the same length
          xmin=-1.1, xmax=1.1, % Axis limits
          ymin=-1.1, ymax=1.1,
          xtick={-1,-0.5,0,0.5,1}, ytick={-1,-0.5,0,0.5,1}, % Tick marks
          no markers,
          title={$dfrac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$},
          view={0}{90},samples=21,domain=-1.1:1.1, y domain=-1.1:1.1, %for direction field
          ]
          addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
          addplot table {y0=-0.5.dat};
          addplot table {y0=0.0.dat};
          addplot table {y0=0.5.dat};
          end{axis}
          end{tikzpicture}

          end{document}




          Code for typesetting at one sweep using option --shell-escape with any LaTeX engine:



          documentclass{article}
          usepackage{amsmath}
          usepackage{pgfplots}
          pgfplotsset{compat=1.8}

          usepackage{filecontents}
          begin{filecontents}{xyz.tex}
          input pst-ode
          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
          %solve dy/dx=x^2 + y^2 - 1 numerically for different initial values of y in the
          %interval x=[-1.1,1.1]; write resulting curves as tables with 100 output points
          %into text files
          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
          %y0=-0.5 --> y0=-0.5.dat
          pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=-0.5}{t | x[0]}{-1.1}{1.1}{100}{-0.5}{t^2+x[0]^2-1}

          %y0=0.0 --> y0=0.0.dat
          pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.0}{t | x[0]}{-1.1}{1.1}{100}{0.0}{t^2+x[0]^2-1}

          %y0=0.5 --> y0=0.5.dat
          pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.5}{t | x[0]}{-1.1}{1.1}{100}{0.5}{t^2+x[0]^2-1}
          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
          bye
          end{filecontents}

          immediatewrite18{tex xyz}
          immediatewrite18{dvips xyz}
          immediatewrite18{ps2pdf -dNOSAFER xyz.ps}

          begin{document}

          begin{tikzpicture}
          begin{axis}[
          axis equal image, % Unit vectors for both axes have the same length
          xmin=-1.1, xmax=1.1, % Axis limits
          ymin=-1.1, ymax=1.1,
          xtick={-1,-0.5,0,0.5,1}, ytick={-1,-0.5,0,0.5,1}, % Tick marks
          no markers,
          title={$dfrac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$},
          view={0}{90},samples=21,domain=-1.1:1.1, y domain=-1.1:1.1, %for direction field
          ]
          addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
          addplot table {y0=-0.5.dat};
          addplot table {y0=0.0.dat};
          addplot table {y0=0.5.dat};
          end{axis}
          end{tikzpicture}

          end{document}





          share|improve this answer





















          • 1





            See my edit for running everything from within one file. Then you do not need the if... structures

            – Herbert
            Oct 17 '13 at 9:17








          • 1





            @Herbert: Thanks a lot. I assimilated your suggestion in the second code block.

            – AlexG
            Oct 17 '13 at 10:41











          • I don't get the three lines, I get the arrows to show, but not the lines. I get an error about not being able to read the tables.

            – MaoYiyi
            Oct 17 '13 at 13:03











          • @MaoYiyi: (1) Copy contents of 2nd code block into a file, say myfile.tex. (2) Run pdflatex --shell-escape myfile. (3) Open myfile.pdf in a PDF reader of your choice. Option --shell-escape is crucial here, as it allows for automatically executing the tex,dvips,ps2pdf chain for producing the data tables in the files y0=*.dat.

            – AlexG
            Oct 17 '13 at 13:14





















          28














          enter image description here



          MWE with Asymptote



          % odeslope.tex:
          %
          documentclass{article}
          usepackage[inline]{asymptote}
          usepackage{lmodern}
          begin{document}
          begin{figure}
          centering
          begin{asy}
          import graph;
          import slopefield;
          import fontsize;
          defaultpen(fontsize(9pt));
          size(200);
          real dy(real x,real y) {return x^2+y^2-1;}
          real xmin=-1, xmax=1;
          real ymin=-0.2, ymax=1;

          add(slopefield(dy,(xmin,ymin),(xmax,ymax),20,deepgreen+0.4bp,Arrow));

          pair C=(0.5,0.4);
          draw(curve(C,dy,(xmin,ymin),(xmax,ymax)),deepblue+1bp);

          label("$C$",C,NE,UnFill);
          dot(C,UnFill);

          xaxis(YEquals(ymin),xmin,xmax,LeftTicks());
          xaxis(YEquals(ymax),xmin,xmax);
          yaxis(XEquals(xmin),ymin,ymax,RightTicks());
          yaxis(XEquals(xmax),ymin,ymax);
          end{asy}
          caption{$frac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$}
          end{figure}
          end{document}
          %
          % Process:
          %
          % pdflatex odeslope.tex
          % asy odeslope-*.asy
          % pdflatex odeslope.tex





          share|improve this answer



















          • 1





            @AlexG: The documentation is humble about it, but the code in slopefield.asy looks more like the Runge–Kutta method.

            – g.kov
            Oct 16 '13 at 14:59






          • 1





            Yes and it seems to apply some automatic step size adaption. Thus, it is quite accurate.

            – AlexG
            Oct 16 '13 at 15:41






          • 7





            @Marc van Dongen: Please, not again. It was once concluded after long and painful discussion that TikZ/PSTriks/Metapost/Asymptote are somewhat equivalent and the community can only benefit from answers that provide alternative approaches to get the desired high quality graphics with TeX and friends.

            – g.kov
            Oct 17 '13 at 10:40






          • 3





            @MarcvanDongen: There was a bit of discussion about the relevance of Asymptote in the comments to tex.stackexchange.com/a/117436/2552, and the votes and lack of opposition on meta.tex.stackexchange.com/q/3518/2552 also seem to be quite a clear indicator that Asymptote can be considered equivalent to TikZ/PSTricks for the purposes of this site. I think the community has kind of come to the conclusion that questions about generating graphics can be answered with different tools (even if the question asks about a particular one) without having to list the pros and cons of the ...

            – Jake
            Oct 17 '13 at 10:55






          • 4





            @AlexG: I know, but as I said, many questions get answers using different tools, even if the question asks for a particular one. The community has more or less agreed on this being a welcome thing (see meta.tex.stackexchange.com/questions/3408/…): Even if the answers might not be relevant to the asker because they're bound to a particular tool, other people will definitely benefit from seeing a range of different approaches.

            – Jake
            Oct 17 '13 at 11:25



















          17














          A PSTricks solution, it can be run with xelatex but that takes a lot of time in difference to latex->dvips->ps2pdf



          documentclass[border=10pt]{standalone}
          usepackage{pst-plot,pst-ode}
          begin{document}

          psset{unit=3}
          begin{pspicture}(-1.2,-1.2)(1.1,1.1)
          psaxes[ticksize=0 4pt,axesstyle=frame,tickstyle=inner,subticks=20,
          Ox=-1,Oy=-1](-1,-1)(1,1)
          psset{arrows=->,algebraic}
          psVectorfield[linecolor=black!60](-0.9,-0.9)(0.9,0.9){ x^2+y^2-1 }
          %y0_a=-0.5
          pstODEsolve[algebraicOutputFormat]{y0_a}{t | x[0]}{-1}{1}{100}{-0.5}{t^2+x[0]^2-1}
          %y0_b=0.0
          pstODEsolve[algebraicOutputFormat]{y0_b}{t | x[0]}{-1}{1}{100}{0.0}{t^2+x[0]^2-1}
          %y0_c=0.5
          pstODEsolve[algebraicOutputFormat]{y0_c}{t | x[0]}{-1}{1}{100}{0.5}{t^2+x[0]^2-1}

          psset{arrows=-,linewidth=1pt}%
          listplot[linecolor=red ]{y0_a}
          listplot[linecolor=green]{y0_b}
          listplot[linecolor=blue ]{y0_c}
          end{pspicture}

          end{document}


          enter image description here






          share|improve this answer

























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "85"
            };
            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%2ftex.stackexchange.com%2fquestions%2f139114%2fdifferential-equation-direction-plot-with-pgfplots%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            32














            Using PGFPlotstable, you can use a naive numerical integration scheme to find the function directly within LaTeX:





            documentclass{article}
            usepackage{pgfplots, pgfplotstable}
            pgfplotsset{compat=1.8}

            usepackage{amsmath}

            pgfplotstableset{
            create on use/x/.style={
            create col/expr={
            pgfplotstablerow/201*2-1
            }
            },
            create on use/y/.style={
            create col/expr accum={
            pgfmathaccuma+(2/201)*(abs(pgfmathaccuma^2)+abs(thisrow{x}^2)-1)
            }{0.6}
            }
            }


            pgfplotstablenew{201}loadedtable

            begin{document}
            begin{tikzpicture}
            begin{axis}[
            view={0}{90},
            domain=-1:1,
            y domain=-1:1,
            xmax=1, ymax=1,
            samples=21
            ]
            addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
            addplot [thick, red] table [x=x, y=y] {loadedtable};
            end{axis}
            end{tikzpicture}

            end{document}





            share|improve this answer


























            • How to you change the x and y values for the viewing window?

              – MaoYiyi
              Oct 17 '13 at 13:00
















            32














            Using PGFPlotstable, you can use a naive numerical integration scheme to find the function directly within LaTeX:





            documentclass{article}
            usepackage{pgfplots, pgfplotstable}
            pgfplotsset{compat=1.8}

            usepackage{amsmath}

            pgfplotstableset{
            create on use/x/.style={
            create col/expr={
            pgfplotstablerow/201*2-1
            }
            },
            create on use/y/.style={
            create col/expr accum={
            pgfmathaccuma+(2/201)*(abs(pgfmathaccuma^2)+abs(thisrow{x}^2)-1)
            }{0.6}
            }
            }


            pgfplotstablenew{201}loadedtable

            begin{document}
            begin{tikzpicture}
            begin{axis}[
            view={0}{90},
            domain=-1:1,
            y domain=-1:1,
            xmax=1, ymax=1,
            samples=21
            ]
            addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
            addplot [thick, red] table [x=x, y=y] {loadedtable};
            end{axis}
            end{tikzpicture}

            end{document}





            share|improve this answer


























            • How to you change the x and y values for the viewing window?

              – MaoYiyi
              Oct 17 '13 at 13:00














            32












            32








            32







            Using PGFPlotstable, you can use a naive numerical integration scheme to find the function directly within LaTeX:





            documentclass{article}
            usepackage{pgfplots, pgfplotstable}
            pgfplotsset{compat=1.8}

            usepackage{amsmath}

            pgfplotstableset{
            create on use/x/.style={
            create col/expr={
            pgfplotstablerow/201*2-1
            }
            },
            create on use/y/.style={
            create col/expr accum={
            pgfmathaccuma+(2/201)*(abs(pgfmathaccuma^2)+abs(thisrow{x}^2)-1)
            }{0.6}
            }
            }


            pgfplotstablenew{201}loadedtable

            begin{document}
            begin{tikzpicture}
            begin{axis}[
            view={0}{90},
            domain=-1:1,
            y domain=-1:1,
            xmax=1, ymax=1,
            samples=21
            ]
            addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
            addplot [thick, red] table [x=x, y=y] {loadedtable};
            end{axis}
            end{tikzpicture}

            end{document}





            share|improve this answer















            Using PGFPlotstable, you can use a naive numerical integration scheme to find the function directly within LaTeX:





            documentclass{article}
            usepackage{pgfplots, pgfplotstable}
            pgfplotsset{compat=1.8}

            usepackage{amsmath}

            pgfplotstableset{
            create on use/x/.style={
            create col/expr={
            pgfplotstablerow/201*2-1
            }
            },
            create on use/y/.style={
            create col/expr accum={
            pgfmathaccuma+(2/201)*(abs(pgfmathaccuma^2)+abs(thisrow{x}^2)-1)
            }{0.6}
            }
            }


            pgfplotstablenew{201}loadedtable

            begin{document}
            begin{tikzpicture}
            begin{axis}[
            view={0}{90},
            domain=-1:1,
            y domain=-1:1,
            xmax=1, ymax=1,
            samples=21
            ]
            addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
            addplot [thick, red] table [x=x, y=y] {loadedtable};
            end{axis}
            end{tikzpicture}

            end{document}






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Oct 16 '13 at 14:25

























            answered Oct 16 '13 at 14:16









            JakeJake

            194k24649762




            194k24649762













            • How to you change the x and y values for the viewing window?

              – MaoYiyi
              Oct 17 '13 at 13:00



















            • How to you change the x and y values for the viewing window?

              – MaoYiyi
              Oct 17 '13 at 13:00

















            How to you change the x and y values for the viewing window?

            – MaoYiyi
            Oct 17 '13 at 13:00





            How to you change the x and y values for the viewing window?

            – MaoYiyi
            Oct 17 '13 at 13:00











            30














            (Sets of) ordinary differential equations (ODE) can be numerically solved using pstODEsolve from the pst-ode Plain-TeX / LaTeX package.



            Integration of the ODEs is done using the Runge-Kutta-Fehlberg method of 4th order with adaptive step size control (RKF45) during the ps2pdf conversion step.



            For plotting packages other than PSTricks, such as pgfplots to be used here, LaTeX must be run twice. The first run, must go the dvips+ps2pdf route, in order to write the solution table into a text file, which is then read and transformed into a chart by your favourite plotting package and TeX engine.



            The first compilation is done like this (option -dNOSAFER is necessary to allow Ghostscript to write files):



            latex myfile
            dvips myfile
            ps2pdf -dNOSAFER myfile.ps


            The second run can involve your preferred toolchain pdflatex, xelatex, latex/dvips/ps2pdf, whatever. It plots the results using pgfplots.



            Alternatively, a single call to your favourite LaTeX engine with option --shell-escape is sufficient if the second code box below is used. (Under the hood, the chain of commands tex, dvips, ps2pdf -dNOSAFER is executed before the document is actually typeset.) Solution provided by Herbert.



            enter image description here



            documentclass{article}
            usepackage{amsmath}
            usepackage{pgfplots}
            pgfplotsset{compat=1.8}

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            usepackage{ifpdf}
            ifpdf
            IfFileExists{y0=-0.5.dat}{}{
            GenericError{}{MessageBreak%
            ===================================MessageBreak
            First, you have to runMessageBreakMessageBreak
            latex jobnameMessageBreak
            dvips jobnameMessageBreak
            ps2pdf -dNOSAFER jobname.psMessageBreakMessageBreak
            to solve the differential equation.MessageBreak
            ===================================}{}{}
            }
            else
            usepackage{pst-ode}

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %solve dy/dx=x^2 + y^2 - 1 numerically for different initial values of y in the
            %interval x=[-1.1,1.1]; write resulting curves as tables with 100 output points
            %into text files
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

            %y0=-0.5 --> y0=-0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{%
            y0=-0.5% %name of the output file `y0=-0.5.dat'
            }{
            t | x[0] %table format in `y0=-0.5.dat': x y
            }{
            -1.1 %integration domain x_min=-1.1
            }{
            1.1 %integration domain x_max=1.1
            }{
            100 %number of output points
            }{
            -0.5 %initial value y0(x_min)
            }{
            t^2+x[0]^2-1 % right hand side of ODE, note the special notation: x --> t, y --> x[0]
            }

            %y0=0.0 --> y0=0.0.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.0}{t | x[0]}{-1.1}{1.1}{100}{0.0}{t^2+x[0]^2-1}

            %y0=0.5 --> y0=0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.5}{t | x[0]}{-1.1}{1.1}{100}{0.5}{t^2+x[0]^2-1}
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            fi

            begin{document}
            IfFileExists{y0=-0.5.dat}{}{dummy textend{document}}

            begin{tikzpicture}
            begin{axis}[
            axis equal image, % Unit vectors for both axes have the same length
            xmin=-1.1, xmax=1.1, % Axis limits
            ymin=-1.1, ymax=1.1,
            xtick={-1,-0.5,0,0.5,1}, ytick={-1,-0.5,0,0.5,1}, % Tick marks
            no markers,
            title={$dfrac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$},
            view={0}{90},samples=21,domain=-1.1:1.1, y domain=-1.1:1.1, %for direction field
            ]
            addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
            addplot table {y0=-0.5.dat};
            addplot table {y0=0.0.dat};
            addplot table {y0=0.5.dat};
            end{axis}
            end{tikzpicture}

            end{document}




            Code for typesetting at one sweep using option --shell-escape with any LaTeX engine:



            documentclass{article}
            usepackage{amsmath}
            usepackage{pgfplots}
            pgfplotsset{compat=1.8}

            usepackage{filecontents}
            begin{filecontents}{xyz.tex}
            input pst-ode
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %solve dy/dx=x^2 + y^2 - 1 numerically for different initial values of y in the
            %interval x=[-1.1,1.1]; write resulting curves as tables with 100 output points
            %into text files
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %y0=-0.5 --> y0=-0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=-0.5}{t | x[0]}{-1.1}{1.1}{100}{-0.5}{t^2+x[0]^2-1}

            %y0=0.0 --> y0=0.0.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.0}{t | x[0]}{-1.1}{1.1}{100}{0.0}{t^2+x[0]^2-1}

            %y0=0.5 --> y0=0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.5}{t | x[0]}{-1.1}{1.1}{100}{0.5}{t^2+x[0]^2-1}
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            bye
            end{filecontents}

            immediatewrite18{tex xyz}
            immediatewrite18{dvips xyz}
            immediatewrite18{ps2pdf -dNOSAFER xyz.ps}

            begin{document}

            begin{tikzpicture}
            begin{axis}[
            axis equal image, % Unit vectors for both axes have the same length
            xmin=-1.1, xmax=1.1, % Axis limits
            ymin=-1.1, ymax=1.1,
            xtick={-1,-0.5,0,0.5,1}, ytick={-1,-0.5,0,0.5,1}, % Tick marks
            no markers,
            title={$dfrac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$},
            view={0}{90},samples=21,domain=-1.1:1.1, y domain=-1.1:1.1, %for direction field
            ]
            addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
            addplot table {y0=-0.5.dat};
            addplot table {y0=0.0.dat};
            addplot table {y0=0.5.dat};
            end{axis}
            end{tikzpicture}

            end{document}





            share|improve this answer





















            • 1





              See my edit for running everything from within one file. Then you do not need the if... structures

              – Herbert
              Oct 17 '13 at 9:17








            • 1





              @Herbert: Thanks a lot. I assimilated your suggestion in the second code block.

              – AlexG
              Oct 17 '13 at 10:41











            • I don't get the three lines, I get the arrows to show, but not the lines. I get an error about not being able to read the tables.

              – MaoYiyi
              Oct 17 '13 at 13:03











            • @MaoYiyi: (1) Copy contents of 2nd code block into a file, say myfile.tex. (2) Run pdflatex --shell-escape myfile. (3) Open myfile.pdf in a PDF reader of your choice. Option --shell-escape is crucial here, as it allows for automatically executing the tex,dvips,ps2pdf chain for producing the data tables in the files y0=*.dat.

              – AlexG
              Oct 17 '13 at 13:14


















            30














            (Sets of) ordinary differential equations (ODE) can be numerically solved using pstODEsolve from the pst-ode Plain-TeX / LaTeX package.



            Integration of the ODEs is done using the Runge-Kutta-Fehlberg method of 4th order with adaptive step size control (RKF45) during the ps2pdf conversion step.



            For plotting packages other than PSTricks, such as pgfplots to be used here, LaTeX must be run twice. The first run, must go the dvips+ps2pdf route, in order to write the solution table into a text file, which is then read and transformed into a chart by your favourite plotting package and TeX engine.



            The first compilation is done like this (option -dNOSAFER is necessary to allow Ghostscript to write files):



            latex myfile
            dvips myfile
            ps2pdf -dNOSAFER myfile.ps


            The second run can involve your preferred toolchain pdflatex, xelatex, latex/dvips/ps2pdf, whatever. It plots the results using pgfplots.



            Alternatively, a single call to your favourite LaTeX engine with option --shell-escape is sufficient if the second code box below is used. (Under the hood, the chain of commands tex, dvips, ps2pdf -dNOSAFER is executed before the document is actually typeset.) Solution provided by Herbert.



            enter image description here



            documentclass{article}
            usepackage{amsmath}
            usepackage{pgfplots}
            pgfplotsset{compat=1.8}

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            usepackage{ifpdf}
            ifpdf
            IfFileExists{y0=-0.5.dat}{}{
            GenericError{}{MessageBreak%
            ===================================MessageBreak
            First, you have to runMessageBreakMessageBreak
            latex jobnameMessageBreak
            dvips jobnameMessageBreak
            ps2pdf -dNOSAFER jobname.psMessageBreakMessageBreak
            to solve the differential equation.MessageBreak
            ===================================}{}{}
            }
            else
            usepackage{pst-ode}

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %solve dy/dx=x^2 + y^2 - 1 numerically for different initial values of y in the
            %interval x=[-1.1,1.1]; write resulting curves as tables with 100 output points
            %into text files
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

            %y0=-0.5 --> y0=-0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{%
            y0=-0.5% %name of the output file `y0=-0.5.dat'
            }{
            t | x[0] %table format in `y0=-0.5.dat': x y
            }{
            -1.1 %integration domain x_min=-1.1
            }{
            1.1 %integration domain x_max=1.1
            }{
            100 %number of output points
            }{
            -0.5 %initial value y0(x_min)
            }{
            t^2+x[0]^2-1 % right hand side of ODE, note the special notation: x --> t, y --> x[0]
            }

            %y0=0.0 --> y0=0.0.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.0}{t | x[0]}{-1.1}{1.1}{100}{0.0}{t^2+x[0]^2-1}

            %y0=0.5 --> y0=0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.5}{t | x[0]}{-1.1}{1.1}{100}{0.5}{t^2+x[0]^2-1}
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            fi

            begin{document}
            IfFileExists{y0=-0.5.dat}{}{dummy textend{document}}

            begin{tikzpicture}
            begin{axis}[
            axis equal image, % Unit vectors for both axes have the same length
            xmin=-1.1, xmax=1.1, % Axis limits
            ymin=-1.1, ymax=1.1,
            xtick={-1,-0.5,0,0.5,1}, ytick={-1,-0.5,0,0.5,1}, % Tick marks
            no markers,
            title={$dfrac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$},
            view={0}{90},samples=21,domain=-1.1:1.1, y domain=-1.1:1.1, %for direction field
            ]
            addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
            addplot table {y0=-0.5.dat};
            addplot table {y0=0.0.dat};
            addplot table {y0=0.5.dat};
            end{axis}
            end{tikzpicture}

            end{document}




            Code for typesetting at one sweep using option --shell-escape with any LaTeX engine:



            documentclass{article}
            usepackage{amsmath}
            usepackage{pgfplots}
            pgfplotsset{compat=1.8}

            usepackage{filecontents}
            begin{filecontents}{xyz.tex}
            input pst-ode
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %solve dy/dx=x^2 + y^2 - 1 numerically for different initial values of y in the
            %interval x=[-1.1,1.1]; write resulting curves as tables with 100 output points
            %into text files
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %y0=-0.5 --> y0=-0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=-0.5}{t | x[0]}{-1.1}{1.1}{100}{-0.5}{t^2+x[0]^2-1}

            %y0=0.0 --> y0=0.0.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.0}{t | x[0]}{-1.1}{1.1}{100}{0.0}{t^2+x[0]^2-1}

            %y0=0.5 --> y0=0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.5}{t | x[0]}{-1.1}{1.1}{100}{0.5}{t^2+x[0]^2-1}
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            bye
            end{filecontents}

            immediatewrite18{tex xyz}
            immediatewrite18{dvips xyz}
            immediatewrite18{ps2pdf -dNOSAFER xyz.ps}

            begin{document}

            begin{tikzpicture}
            begin{axis}[
            axis equal image, % Unit vectors for both axes have the same length
            xmin=-1.1, xmax=1.1, % Axis limits
            ymin=-1.1, ymax=1.1,
            xtick={-1,-0.5,0,0.5,1}, ytick={-1,-0.5,0,0.5,1}, % Tick marks
            no markers,
            title={$dfrac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$},
            view={0}{90},samples=21,domain=-1.1:1.1, y domain=-1.1:1.1, %for direction field
            ]
            addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
            addplot table {y0=-0.5.dat};
            addplot table {y0=0.0.dat};
            addplot table {y0=0.5.dat};
            end{axis}
            end{tikzpicture}

            end{document}





            share|improve this answer





















            • 1





              See my edit for running everything from within one file. Then you do not need the if... structures

              – Herbert
              Oct 17 '13 at 9:17








            • 1





              @Herbert: Thanks a lot. I assimilated your suggestion in the second code block.

              – AlexG
              Oct 17 '13 at 10:41











            • I don't get the three lines, I get the arrows to show, but not the lines. I get an error about not being able to read the tables.

              – MaoYiyi
              Oct 17 '13 at 13:03











            • @MaoYiyi: (1) Copy contents of 2nd code block into a file, say myfile.tex. (2) Run pdflatex --shell-escape myfile. (3) Open myfile.pdf in a PDF reader of your choice. Option --shell-escape is crucial here, as it allows for automatically executing the tex,dvips,ps2pdf chain for producing the data tables in the files y0=*.dat.

              – AlexG
              Oct 17 '13 at 13:14
















            30












            30








            30







            (Sets of) ordinary differential equations (ODE) can be numerically solved using pstODEsolve from the pst-ode Plain-TeX / LaTeX package.



            Integration of the ODEs is done using the Runge-Kutta-Fehlberg method of 4th order with adaptive step size control (RKF45) during the ps2pdf conversion step.



            For plotting packages other than PSTricks, such as pgfplots to be used here, LaTeX must be run twice. The first run, must go the dvips+ps2pdf route, in order to write the solution table into a text file, which is then read and transformed into a chart by your favourite plotting package and TeX engine.



            The first compilation is done like this (option -dNOSAFER is necessary to allow Ghostscript to write files):



            latex myfile
            dvips myfile
            ps2pdf -dNOSAFER myfile.ps


            The second run can involve your preferred toolchain pdflatex, xelatex, latex/dvips/ps2pdf, whatever. It plots the results using pgfplots.



            Alternatively, a single call to your favourite LaTeX engine with option --shell-escape is sufficient if the second code box below is used. (Under the hood, the chain of commands tex, dvips, ps2pdf -dNOSAFER is executed before the document is actually typeset.) Solution provided by Herbert.



            enter image description here



            documentclass{article}
            usepackage{amsmath}
            usepackage{pgfplots}
            pgfplotsset{compat=1.8}

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            usepackage{ifpdf}
            ifpdf
            IfFileExists{y0=-0.5.dat}{}{
            GenericError{}{MessageBreak%
            ===================================MessageBreak
            First, you have to runMessageBreakMessageBreak
            latex jobnameMessageBreak
            dvips jobnameMessageBreak
            ps2pdf -dNOSAFER jobname.psMessageBreakMessageBreak
            to solve the differential equation.MessageBreak
            ===================================}{}{}
            }
            else
            usepackage{pst-ode}

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %solve dy/dx=x^2 + y^2 - 1 numerically for different initial values of y in the
            %interval x=[-1.1,1.1]; write resulting curves as tables with 100 output points
            %into text files
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

            %y0=-0.5 --> y0=-0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{%
            y0=-0.5% %name of the output file `y0=-0.5.dat'
            }{
            t | x[0] %table format in `y0=-0.5.dat': x y
            }{
            -1.1 %integration domain x_min=-1.1
            }{
            1.1 %integration domain x_max=1.1
            }{
            100 %number of output points
            }{
            -0.5 %initial value y0(x_min)
            }{
            t^2+x[0]^2-1 % right hand side of ODE, note the special notation: x --> t, y --> x[0]
            }

            %y0=0.0 --> y0=0.0.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.0}{t | x[0]}{-1.1}{1.1}{100}{0.0}{t^2+x[0]^2-1}

            %y0=0.5 --> y0=0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.5}{t | x[0]}{-1.1}{1.1}{100}{0.5}{t^2+x[0]^2-1}
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            fi

            begin{document}
            IfFileExists{y0=-0.5.dat}{}{dummy textend{document}}

            begin{tikzpicture}
            begin{axis}[
            axis equal image, % Unit vectors for both axes have the same length
            xmin=-1.1, xmax=1.1, % Axis limits
            ymin=-1.1, ymax=1.1,
            xtick={-1,-0.5,0,0.5,1}, ytick={-1,-0.5,0,0.5,1}, % Tick marks
            no markers,
            title={$dfrac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$},
            view={0}{90},samples=21,domain=-1.1:1.1, y domain=-1.1:1.1, %for direction field
            ]
            addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
            addplot table {y0=-0.5.dat};
            addplot table {y0=0.0.dat};
            addplot table {y0=0.5.dat};
            end{axis}
            end{tikzpicture}

            end{document}




            Code for typesetting at one sweep using option --shell-escape with any LaTeX engine:



            documentclass{article}
            usepackage{amsmath}
            usepackage{pgfplots}
            pgfplotsset{compat=1.8}

            usepackage{filecontents}
            begin{filecontents}{xyz.tex}
            input pst-ode
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %solve dy/dx=x^2 + y^2 - 1 numerically for different initial values of y in the
            %interval x=[-1.1,1.1]; write resulting curves as tables with 100 output points
            %into text files
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %y0=-0.5 --> y0=-0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=-0.5}{t | x[0]}{-1.1}{1.1}{100}{-0.5}{t^2+x[0]^2-1}

            %y0=0.0 --> y0=0.0.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.0}{t | x[0]}{-1.1}{1.1}{100}{0.0}{t^2+x[0]^2-1}

            %y0=0.5 --> y0=0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.5}{t | x[0]}{-1.1}{1.1}{100}{0.5}{t^2+x[0]^2-1}
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            bye
            end{filecontents}

            immediatewrite18{tex xyz}
            immediatewrite18{dvips xyz}
            immediatewrite18{ps2pdf -dNOSAFER xyz.ps}

            begin{document}

            begin{tikzpicture}
            begin{axis}[
            axis equal image, % Unit vectors for both axes have the same length
            xmin=-1.1, xmax=1.1, % Axis limits
            ymin=-1.1, ymax=1.1,
            xtick={-1,-0.5,0,0.5,1}, ytick={-1,-0.5,0,0.5,1}, % Tick marks
            no markers,
            title={$dfrac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$},
            view={0}{90},samples=21,domain=-1.1:1.1, y domain=-1.1:1.1, %for direction field
            ]
            addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
            addplot table {y0=-0.5.dat};
            addplot table {y0=0.0.dat};
            addplot table {y0=0.5.dat};
            end{axis}
            end{tikzpicture}

            end{document}





            share|improve this answer















            (Sets of) ordinary differential equations (ODE) can be numerically solved using pstODEsolve from the pst-ode Plain-TeX / LaTeX package.



            Integration of the ODEs is done using the Runge-Kutta-Fehlberg method of 4th order with adaptive step size control (RKF45) during the ps2pdf conversion step.



            For plotting packages other than PSTricks, such as pgfplots to be used here, LaTeX must be run twice. The first run, must go the dvips+ps2pdf route, in order to write the solution table into a text file, which is then read and transformed into a chart by your favourite plotting package and TeX engine.



            The first compilation is done like this (option -dNOSAFER is necessary to allow Ghostscript to write files):



            latex myfile
            dvips myfile
            ps2pdf -dNOSAFER myfile.ps


            The second run can involve your preferred toolchain pdflatex, xelatex, latex/dvips/ps2pdf, whatever. It plots the results using pgfplots.



            Alternatively, a single call to your favourite LaTeX engine with option --shell-escape is sufficient if the second code box below is used. (Under the hood, the chain of commands tex, dvips, ps2pdf -dNOSAFER is executed before the document is actually typeset.) Solution provided by Herbert.



            enter image description here



            documentclass{article}
            usepackage{amsmath}
            usepackage{pgfplots}
            pgfplotsset{compat=1.8}

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            usepackage{ifpdf}
            ifpdf
            IfFileExists{y0=-0.5.dat}{}{
            GenericError{}{MessageBreak%
            ===================================MessageBreak
            First, you have to runMessageBreakMessageBreak
            latex jobnameMessageBreak
            dvips jobnameMessageBreak
            ps2pdf -dNOSAFER jobname.psMessageBreakMessageBreak
            to solve the differential equation.MessageBreak
            ===================================}{}{}
            }
            else
            usepackage{pst-ode}

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %solve dy/dx=x^2 + y^2 - 1 numerically for different initial values of y in the
            %interval x=[-1.1,1.1]; write resulting curves as tables with 100 output points
            %into text files
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

            %y0=-0.5 --> y0=-0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{%
            y0=-0.5% %name of the output file `y0=-0.5.dat'
            }{
            t | x[0] %table format in `y0=-0.5.dat': x y
            }{
            -1.1 %integration domain x_min=-1.1
            }{
            1.1 %integration domain x_max=1.1
            }{
            100 %number of output points
            }{
            -0.5 %initial value y0(x_min)
            }{
            t^2+x[0]^2-1 % right hand side of ODE, note the special notation: x --> t, y --> x[0]
            }

            %y0=0.0 --> y0=0.0.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.0}{t | x[0]}{-1.1}{1.1}{100}{0.0}{t^2+x[0]^2-1}

            %y0=0.5 --> y0=0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.5}{t | x[0]}{-1.1}{1.1}{100}{0.5}{t^2+x[0]^2-1}
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            fi

            begin{document}
            IfFileExists{y0=-0.5.dat}{}{dummy textend{document}}

            begin{tikzpicture}
            begin{axis}[
            axis equal image, % Unit vectors for both axes have the same length
            xmin=-1.1, xmax=1.1, % Axis limits
            ymin=-1.1, ymax=1.1,
            xtick={-1,-0.5,0,0.5,1}, ytick={-1,-0.5,0,0.5,1}, % Tick marks
            no markers,
            title={$dfrac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$},
            view={0}{90},samples=21,domain=-1.1:1.1, y domain=-1.1:1.1, %for direction field
            ]
            addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
            addplot table {y0=-0.5.dat};
            addplot table {y0=0.0.dat};
            addplot table {y0=0.5.dat};
            end{axis}
            end{tikzpicture}

            end{document}




            Code for typesetting at one sweep using option --shell-escape with any LaTeX engine:



            documentclass{article}
            usepackage{amsmath}
            usepackage{pgfplots}
            pgfplotsset{compat=1.8}

            usepackage{filecontents}
            begin{filecontents}{xyz.tex}
            input pst-ode
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %solve dy/dx=x^2 + y^2 - 1 numerically for different initial values of y in the
            %interval x=[-1.1,1.1]; write resulting curves as tables with 100 output points
            %into text files
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %y0=-0.5 --> y0=-0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=-0.5}{t | x[0]}{-1.1}{1.1}{100}{-0.5}{t^2+x[0]^2-1}

            %y0=0.0 --> y0=0.0.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.0}{t | x[0]}{-1.1}{1.1}{100}{0.0}{t^2+x[0]^2-1}

            %y0=0.5 --> y0=0.5.dat
            pstODEsolve[algebraicOutputFormat,algebraic,saveData]{y0=0.5}{t | x[0]}{-1.1}{1.1}{100}{0.5}{t^2+x[0]^2-1}
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            bye
            end{filecontents}

            immediatewrite18{tex xyz}
            immediatewrite18{dvips xyz}
            immediatewrite18{ps2pdf -dNOSAFER xyz.ps}

            begin{document}

            begin{tikzpicture}
            begin{axis}[
            axis equal image, % Unit vectors for both axes have the same length
            xmin=-1.1, xmax=1.1, % Axis limits
            ymin=-1.1, ymax=1.1,
            xtick={-1,-0.5,0,0.5,1}, ytick={-1,-0.5,0,0.5,1}, % Tick marks
            no markers,
            title={$dfrac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$},
            view={0}{90},samples=21,domain=-1.1:1.1, y domain=-1.1:1.1, %for direction field
            ]
            addplot3 [gray, quiver={u={1}, v={x^2+y^2-1}, scale arrows=0.075, every arrow/.append style={-latex}}] (x,y,0);
            addplot table {y0=-0.5.dat};
            addplot table {y0=0.0.dat};
            addplot table {y0=0.5.dat};
            end{axis}
            end{tikzpicture}

            end{document}






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 8 '18 at 10:55

























            answered Oct 16 '13 at 14:04









            AlexGAlexG

            32.8k479145




            32.8k479145








            • 1





              See my edit for running everything from within one file. Then you do not need the if... structures

              – Herbert
              Oct 17 '13 at 9:17








            • 1





              @Herbert: Thanks a lot. I assimilated your suggestion in the second code block.

              – AlexG
              Oct 17 '13 at 10:41











            • I don't get the three lines, I get the arrows to show, but not the lines. I get an error about not being able to read the tables.

              – MaoYiyi
              Oct 17 '13 at 13:03











            • @MaoYiyi: (1) Copy contents of 2nd code block into a file, say myfile.tex. (2) Run pdflatex --shell-escape myfile. (3) Open myfile.pdf in a PDF reader of your choice. Option --shell-escape is crucial here, as it allows for automatically executing the tex,dvips,ps2pdf chain for producing the data tables in the files y0=*.dat.

              – AlexG
              Oct 17 '13 at 13:14
















            • 1





              See my edit for running everything from within one file. Then you do not need the if... structures

              – Herbert
              Oct 17 '13 at 9:17








            • 1





              @Herbert: Thanks a lot. I assimilated your suggestion in the second code block.

              – AlexG
              Oct 17 '13 at 10:41











            • I don't get the three lines, I get the arrows to show, but not the lines. I get an error about not being able to read the tables.

              – MaoYiyi
              Oct 17 '13 at 13:03











            • @MaoYiyi: (1) Copy contents of 2nd code block into a file, say myfile.tex. (2) Run pdflatex --shell-escape myfile. (3) Open myfile.pdf in a PDF reader of your choice. Option --shell-escape is crucial here, as it allows for automatically executing the tex,dvips,ps2pdf chain for producing the data tables in the files y0=*.dat.

              – AlexG
              Oct 17 '13 at 13:14










            1




            1





            See my edit for running everything from within one file. Then you do not need the if... structures

            – Herbert
            Oct 17 '13 at 9:17







            See my edit for running everything from within one file. Then you do not need the if... structures

            – Herbert
            Oct 17 '13 at 9:17






            1




            1





            @Herbert: Thanks a lot. I assimilated your suggestion in the second code block.

            – AlexG
            Oct 17 '13 at 10:41





            @Herbert: Thanks a lot. I assimilated your suggestion in the second code block.

            – AlexG
            Oct 17 '13 at 10:41













            I don't get the three lines, I get the arrows to show, but not the lines. I get an error about not being able to read the tables.

            – MaoYiyi
            Oct 17 '13 at 13:03





            I don't get the three lines, I get the arrows to show, but not the lines. I get an error about not being able to read the tables.

            – MaoYiyi
            Oct 17 '13 at 13:03













            @MaoYiyi: (1) Copy contents of 2nd code block into a file, say myfile.tex. (2) Run pdflatex --shell-escape myfile. (3) Open myfile.pdf in a PDF reader of your choice. Option --shell-escape is crucial here, as it allows for automatically executing the tex,dvips,ps2pdf chain for producing the data tables in the files y0=*.dat.

            – AlexG
            Oct 17 '13 at 13:14







            @MaoYiyi: (1) Copy contents of 2nd code block into a file, say myfile.tex. (2) Run pdflatex --shell-escape myfile. (3) Open myfile.pdf in a PDF reader of your choice. Option --shell-escape is crucial here, as it allows for automatically executing the tex,dvips,ps2pdf chain for producing the data tables in the files y0=*.dat.

            – AlexG
            Oct 17 '13 at 13:14













            28














            enter image description here



            MWE with Asymptote



            % odeslope.tex:
            %
            documentclass{article}
            usepackage[inline]{asymptote}
            usepackage{lmodern}
            begin{document}
            begin{figure}
            centering
            begin{asy}
            import graph;
            import slopefield;
            import fontsize;
            defaultpen(fontsize(9pt));
            size(200);
            real dy(real x,real y) {return x^2+y^2-1;}
            real xmin=-1, xmax=1;
            real ymin=-0.2, ymax=1;

            add(slopefield(dy,(xmin,ymin),(xmax,ymax),20,deepgreen+0.4bp,Arrow));

            pair C=(0.5,0.4);
            draw(curve(C,dy,(xmin,ymin),(xmax,ymax)),deepblue+1bp);

            label("$C$",C,NE,UnFill);
            dot(C,UnFill);

            xaxis(YEquals(ymin),xmin,xmax,LeftTicks());
            xaxis(YEquals(ymax),xmin,xmax);
            yaxis(XEquals(xmin),ymin,ymax,RightTicks());
            yaxis(XEquals(xmax),ymin,ymax);
            end{asy}
            caption{$frac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$}
            end{figure}
            end{document}
            %
            % Process:
            %
            % pdflatex odeslope.tex
            % asy odeslope-*.asy
            % pdflatex odeslope.tex





            share|improve this answer



















            • 1





              @AlexG: The documentation is humble about it, but the code in slopefield.asy looks more like the Runge–Kutta method.

              – g.kov
              Oct 16 '13 at 14:59






            • 1





              Yes and it seems to apply some automatic step size adaption. Thus, it is quite accurate.

              – AlexG
              Oct 16 '13 at 15:41






            • 7





              @Marc van Dongen: Please, not again. It was once concluded after long and painful discussion that TikZ/PSTriks/Metapost/Asymptote are somewhat equivalent and the community can only benefit from answers that provide alternative approaches to get the desired high quality graphics with TeX and friends.

              – g.kov
              Oct 17 '13 at 10:40






            • 3





              @MarcvanDongen: There was a bit of discussion about the relevance of Asymptote in the comments to tex.stackexchange.com/a/117436/2552, and the votes and lack of opposition on meta.tex.stackexchange.com/q/3518/2552 also seem to be quite a clear indicator that Asymptote can be considered equivalent to TikZ/PSTricks for the purposes of this site. I think the community has kind of come to the conclusion that questions about generating graphics can be answered with different tools (even if the question asks about a particular one) without having to list the pros and cons of the ...

              – Jake
              Oct 17 '13 at 10:55






            • 4





              @AlexG: I know, but as I said, many questions get answers using different tools, even if the question asks for a particular one. The community has more or less agreed on this being a welcome thing (see meta.tex.stackexchange.com/questions/3408/…): Even if the answers might not be relevant to the asker because they're bound to a particular tool, other people will definitely benefit from seeing a range of different approaches.

              – Jake
              Oct 17 '13 at 11:25
















            28














            enter image description here



            MWE with Asymptote



            % odeslope.tex:
            %
            documentclass{article}
            usepackage[inline]{asymptote}
            usepackage{lmodern}
            begin{document}
            begin{figure}
            centering
            begin{asy}
            import graph;
            import slopefield;
            import fontsize;
            defaultpen(fontsize(9pt));
            size(200);
            real dy(real x,real y) {return x^2+y^2-1;}
            real xmin=-1, xmax=1;
            real ymin=-0.2, ymax=1;

            add(slopefield(dy,(xmin,ymin),(xmax,ymax),20,deepgreen+0.4bp,Arrow));

            pair C=(0.5,0.4);
            draw(curve(C,dy,(xmin,ymin),(xmax,ymax)),deepblue+1bp);

            label("$C$",C,NE,UnFill);
            dot(C,UnFill);

            xaxis(YEquals(ymin),xmin,xmax,LeftTicks());
            xaxis(YEquals(ymax),xmin,xmax);
            yaxis(XEquals(xmin),ymin,ymax,RightTicks());
            yaxis(XEquals(xmax),ymin,ymax);
            end{asy}
            caption{$frac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$}
            end{figure}
            end{document}
            %
            % Process:
            %
            % pdflatex odeslope.tex
            % asy odeslope-*.asy
            % pdflatex odeslope.tex





            share|improve this answer



















            • 1





              @AlexG: The documentation is humble about it, but the code in slopefield.asy looks more like the Runge–Kutta method.

              – g.kov
              Oct 16 '13 at 14:59






            • 1





              Yes and it seems to apply some automatic step size adaption. Thus, it is quite accurate.

              – AlexG
              Oct 16 '13 at 15:41






            • 7





              @Marc van Dongen: Please, not again. It was once concluded after long and painful discussion that TikZ/PSTriks/Metapost/Asymptote are somewhat equivalent and the community can only benefit from answers that provide alternative approaches to get the desired high quality graphics with TeX and friends.

              – g.kov
              Oct 17 '13 at 10:40






            • 3





              @MarcvanDongen: There was a bit of discussion about the relevance of Asymptote in the comments to tex.stackexchange.com/a/117436/2552, and the votes and lack of opposition on meta.tex.stackexchange.com/q/3518/2552 also seem to be quite a clear indicator that Asymptote can be considered equivalent to TikZ/PSTricks for the purposes of this site. I think the community has kind of come to the conclusion that questions about generating graphics can be answered with different tools (even if the question asks about a particular one) without having to list the pros and cons of the ...

              – Jake
              Oct 17 '13 at 10:55






            • 4





              @AlexG: I know, but as I said, many questions get answers using different tools, even if the question asks for a particular one. The community has more or less agreed on this being a welcome thing (see meta.tex.stackexchange.com/questions/3408/…): Even if the answers might not be relevant to the asker because they're bound to a particular tool, other people will definitely benefit from seeing a range of different approaches.

              – Jake
              Oct 17 '13 at 11:25














            28












            28








            28







            enter image description here



            MWE with Asymptote



            % odeslope.tex:
            %
            documentclass{article}
            usepackage[inline]{asymptote}
            usepackage{lmodern}
            begin{document}
            begin{figure}
            centering
            begin{asy}
            import graph;
            import slopefield;
            import fontsize;
            defaultpen(fontsize(9pt));
            size(200);
            real dy(real x,real y) {return x^2+y^2-1;}
            real xmin=-1, xmax=1;
            real ymin=-0.2, ymax=1;

            add(slopefield(dy,(xmin,ymin),(xmax,ymax),20,deepgreen+0.4bp,Arrow));

            pair C=(0.5,0.4);
            draw(curve(C,dy,(xmin,ymin),(xmax,ymax)),deepblue+1bp);

            label("$C$",C,NE,UnFill);
            dot(C,UnFill);

            xaxis(YEquals(ymin),xmin,xmax,LeftTicks());
            xaxis(YEquals(ymax),xmin,xmax);
            yaxis(XEquals(xmin),ymin,ymax,RightTicks());
            yaxis(XEquals(xmax),ymin,ymax);
            end{asy}
            caption{$frac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$}
            end{figure}
            end{document}
            %
            % Process:
            %
            % pdflatex odeslope.tex
            % asy odeslope-*.asy
            % pdflatex odeslope.tex





            share|improve this answer













            enter image description here



            MWE with Asymptote



            % odeslope.tex:
            %
            documentclass{article}
            usepackage[inline]{asymptote}
            usepackage{lmodern}
            begin{document}
            begin{figure}
            centering
            begin{asy}
            import graph;
            import slopefield;
            import fontsize;
            defaultpen(fontsize(9pt));
            size(200);
            real dy(real x,real y) {return x^2+y^2-1;}
            real xmin=-1, xmax=1;
            real ymin=-0.2, ymax=1;

            add(slopefield(dy,(xmin,ymin),(xmax,ymax),20,deepgreen+0.4bp,Arrow));

            pair C=(0.5,0.4);
            draw(curve(C,dy,(xmin,ymin),(xmax,ymax)),deepblue+1bp);

            label("$C$",C,NE,UnFill);
            dot(C,UnFill);

            xaxis(YEquals(ymin),xmin,xmax,LeftTicks());
            xaxis(YEquals(ymax),xmin,xmax);
            yaxis(XEquals(xmin),ymin,ymax,RightTicks());
            yaxis(XEquals(xmax),ymin,ymax);
            end{asy}
            caption{$frac{mathrm{d}y}{mathrm{d}x}=x^2+y^2-1$}
            end{figure}
            end{document}
            %
            % Process:
            %
            % pdflatex odeslope.tex
            % asy odeslope-*.asy
            % pdflatex odeslope.tex






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 16 '13 at 13:42









            g.kovg.kov

            17.2k13976




            17.2k13976








            • 1





              @AlexG: The documentation is humble about it, but the code in slopefield.asy looks more like the Runge–Kutta method.

              – g.kov
              Oct 16 '13 at 14:59






            • 1





              Yes and it seems to apply some automatic step size adaption. Thus, it is quite accurate.

              – AlexG
              Oct 16 '13 at 15:41






            • 7





              @Marc van Dongen: Please, not again. It was once concluded after long and painful discussion that TikZ/PSTriks/Metapost/Asymptote are somewhat equivalent and the community can only benefit from answers that provide alternative approaches to get the desired high quality graphics with TeX and friends.

              – g.kov
              Oct 17 '13 at 10:40






            • 3





              @MarcvanDongen: There was a bit of discussion about the relevance of Asymptote in the comments to tex.stackexchange.com/a/117436/2552, and the votes and lack of opposition on meta.tex.stackexchange.com/q/3518/2552 also seem to be quite a clear indicator that Asymptote can be considered equivalent to TikZ/PSTricks for the purposes of this site. I think the community has kind of come to the conclusion that questions about generating graphics can be answered with different tools (even if the question asks about a particular one) without having to list the pros and cons of the ...

              – Jake
              Oct 17 '13 at 10:55






            • 4





              @AlexG: I know, but as I said, many questions get answers using different tools, even if the question asks for a particular one. The community has more or less agreed on this being a welcome thing (see meta.tex.stackexchange.com/questions/3408/…): Even if the answers might not be relevant to the asker because they're bound to a particular tool, other people will definitely benefit from seeing a range of different approaches.

              – Jake
              Oct 17 '13 at 11:25














            • 1





              @AlexG: The documentation is humble about it, but the code in slopefield.asy looks more like the Runge–Kutta method.

              – g.kov
              Oct 16 '13 at 14:59






            • 1





              Yes and it seems to apply some automatic step size adaption. Thus, it is quite accurate.

              – AlexG
              Oct 16 '13 at 15:41






            • 7





              @Marc van Dongen: Please, not again. It was once concluded after long and painful discussion that TikZ/PSTriks/Metapost/Asymptote are somewhat equivalent and the community can only benefit from answers that provide alternative approaches to get the desired high quality graphics with TeX and friends.

              – g.kov
              Oct 17 '13 at 10:40






            • 3





              @MarcvanDongen: There was a bit of discussion about the relevance of Asymptote in the comments to tex.stackexchange.com/a/117436/2552, and the votes and lack of opposition on meta.tex.stackexchange.com/q/3518/2552 also seem to be quite a clear indicator that Asymptote can be considered equivalent to TikZ/PSTricks for the purposes of this site. I think the community has kind of come to the conclusion that questions about generating graphics can be answered with different tools (even if the question asks about a particular one) without having to list the pros and cons of the ...

              – Jake
              Oct 17 '13 at 10:55






            • 4





              @AlexG: I know, but as I said, many questions get answers using different tools, even if the question asks for a particular one. The community has more or less agreed on this being a welcome thing (see meta.tex.stackexchange.com/questions/3408/…): Even if the answers might not be relevant to the asker because they're bound to a particular tool, other people will definitely benefit from seeing a range of different approaches.

              – Jake
              Oct 17 '13 at 11:25








            1




            1





            @AlexG: The documentation is humble about it, but the code in slopefield.asy looks more like the Runge–Kutta method.

            – g.kov
            Oct 16 '13 at 14:59





            @AlexG: The documentation is humble about it, but the code in slopefield.asy looks more like the Runge–Kutta method.

            – g.kov
            Oct 16 '13 at 14:59




            1




            1





            Yes and it seems to apply some automatic step size adaption. Thus, it is quite accurate.

            – AlexG
            Oct 16 '13 at 15:41





            Yes and it seems to apply some automatic step size adaption. Thus, it is quite accurate.

            – AlexG
            Oct 16 '13 at 15:41




            7




            7





            @Marc van Dongen: Please, not again. It was once concluded after long and painful discussion that TikZ/PSTriks/Metapost/Asymptote are somewhat equivalent and the community can only benefit from answers that provide alternative approaches to get the desired high quality graphics with TeX and friends.

            – g.kov
            Oct 17 '13 at 10:40





            @Marc van Dongen: Please, not again. It was once concluded after long and painful discussion that TikZ/PSTriks/Metapost/Asymptote are somewhat equivalent and the community can only benefit from answers that provide alternative approaches to get the desired high quality graphics with TeX and friends.

            – g.kov
            Oct 17 '13 at 10:40




            3




            3





            @MarcvanDongen: There was a bit of discussion about the relevance of Asymptote in the comments to tex.stackexchange.com/a/117436/2552, and the votes and lack of opposition on meta.tex.stackexchange.com/q/3518/2552 also seem to be quite a clear indicator that Asymptote can be considered equivalent to TikZ/PSTricks for the purposes of this site. I think the community has kind of come to the conclusion that questions about generating graphics can be answered with different tools (even if the question asks about a particular one) without having to list the pros and cons of the ...

            – Jake
            Oct 17 '13 at 10:55





            @MarcvanDongen: There was a bit of discussion about the relevance of Asymptote in the comments to tex.stackexchange.com/a/117436/2552, and the votes and lack of opposition on meta.tex.stackexchange.com/q/3518/2552 also seem to be quite a clear indicator that Asymptote can be considered equivalent to TikZ/PSTricks for the purposes of this site. I think the community has kind of come to the conclusion that questions about generating graphics can be answered with different tools (even if the question asks about a particular one) without having to list the pros and cons of the ...

            – Jake
            Oct 17 '13 at 10:55




            4




            4





            @AlexG: I know, but as I said, many questions get answers using different tools, even if the question asks for a particular one. The community has more or less agreed on this being a welcome thing (see meta.tex.stackexchange.com/questions/3408/…): Even if the answers might not be relevant to the asker because they're bound to a particular tool, other people will definitely benefit from seeing a range of different approaches.

            – Jake
            Oct 17 '13 at 11:25





            @AlexG: I know, but as I said, many questions get answers using different tools, even if the question asks for a particular one. The community has more or less agreed on this being a welcome thing (see meta.tex.stackexchange.com/questions/3408/…): Even if the answers might not be relevant to the asker because they're bound to a particular tool, other people will definitely benefit from seeing a range of different approaches.

            – Jake
            Oct 17 '13 at 11:25











            17














            A PSTricks solution, it can be run with xelatex but that takes a lot of time in difference to latex->dvips->ps2pdf



            documentclass[border=10pt]{standalone}
            usepackage{pst-plot,pst-ode}
            begin{document}

            psset{unit=3}
            begin{pspicture}(-1.2,-1.2)(1.1,1.1)
            psaxes[ticksize=0 4pt,axesstyle=frame,tickstyle=inner,subticks=20,
            Ox=-1,Oy=-1](-1,-1)(1,1)
            psset{arrows=->,algebraic}
            psVectorfield[linecolor=black!60](-0.9,-0.9)(0.9,0.9){ x^2+y^2-1 }
            %y0_a=-0.5
            pstODEsolve[algebraicOutputFormat]{y0_a}{t | x[0]}{-1}{1}{100}{-0.5}{t^2+x[0]^2-1}
            %y0_b=0.0
            pstODEsolve[algebraicOutputFormat]{y0_b}{t | x[0]}{-1}{1}{100}{0.0}{t^2+x[0]^2-1}
            %y0_c=0.5
            pstODEsolve[algebraicOutputFormat]{y0_c}{t | x[0]}{-1}{1}{100}{0.5}{t^2+x[0]^2-1}

            psset{arrows=-,linewidth=1pt}%
            listplot[linecolor=red ]{y0_a}
            listplot[linecolor=green]{y0_b}
            listplot[linecolor=blue ]{y0_c}
            end{pspicture}

            end{document}


            enter image description here






            share|improve this answer






























              17














              A PSTricks solution, it can be run with xelatex but that takes a lot of time in difference to latex->dvips->ps2pdf



              documentclass[border=10pt]{standalone}
              usepackage{pst-plot,pst-ode}
              begin{document}

              psset{unit=3}
              begin{pspicture}(-1.2,-1.2)(1.1,1.1)
              psaxes[ticksize=0 4pt,axesstyle=frame,tickstyle=inner,subticks=20,
              Ox=-1,Oy=-1](-1,-1)(1,1)
              psset{arrows=->,algebraic}
              psVectorfield[linecolor=black!60](-0.9,-0.9)(0.9,0.9){ x^2+y^2-1 }
              %y0_a=-0.5
              pstODEsolve[algebraicOutputFormat]{y0_a}{t | x[0]}{-1}{1}{100}{-0.5}{t^2+x[0]^2-1}
              %y0_b=0.0
              pstODEsolve[algebraicOutputFormat]{y0_b}{t | x[0]}{-1}{1}{100}{0.0}{t^2+x[0]^2-1}
              %y0_c=0.5
              pstODEsolve[algebraicOutputFormat]{y0_c}{t | x[0]}{-1}{1}{100}{0.5}{t^2+x[0]^2-1}

              psset{arrows=-,linewidth=1pt}%
              listplot[linecolor=red ]{y0_a}
              listplot[linecolor=green]{y0_b}
              listplot[linecolor=blue ]{y0_c}
              end{pspicture}

              end{document}


              enter image description here






              share|improve this answer




























                17












                17








                17







                A PSTricks solution, it can be run with xelatex but that takes a lot of time in difference to latex->dvips->ps2pdf



                documentclass[border=10pt]{standalone}
                usepackage{pst-plot,pst-ode}
                begin{document}

                psset{unit=3}
                begin{pspicture}(-1.2,-1.2)(1.1,1.1)
                psaxes[ticksize=0 4pt,axesstyle=frame,tickstyle=inner,subticks=20,
                Ox=-1,Oy=-1](-1,-1)(1,1)
                psset{arrows=->,algebraic}
                psVectorfield[linecolor=black!60](-0.9,-0.9)(0.9,0.9){ x^2+y^2-1 }
                %y0_a=-0.5
                pstODEsolve[algebraicOutputFormat]{y0_a}{t | x[0]}{-1}{1}{100}{-0.5}{t^2+x[0]^2-1}
                %y0_b=0.0
                pstODEsolve[algebraicOutputFormat]{y0_b}{t | x[0]}{-1}{1}{100}{0.0}{t^2+x[0]^2-1}
                %y0_c=0.5
                pstODEsolve[algebraicOutputFormat]{y0_c}{t | x[0]}{-1}{1}{100}{0.5}{t^2+x[0]^2-1}

                psset{arrows=-,linewidth=1pt}%
                listplot[linecolor=red ]{y0_a}
                listplot[linecolor=green]{y0_b}
                listplot[linecolor=blue ]{y0_c}
                end{pspicture}

                end{document}


                enter image description here






                share|improve this answer















                A PSTricks solution, it can be run with xelatex but that takes a lot of time in difference to latex->dvips->ps2pdf



                documentclass[border=10pt]{standalone}
                usepackage{pst-plot,pst-ode}
                begin{document}

                psset{unit=3}
                begin{pspicture}(-1.2,-1.2)(1.1,1.1)
                psaxes[ticksize=0 4pt,axesstyle=frame,tickstyle=inner,subticks=20,
                Ox=-1,Oy=-1](-1,-1)(1,1)
                psset{arrows=->,algebraic}
                psVectorfield[linecolor=black!60](-0.9,-0.9)(0.9,0.9){ x^2+y^2-1 }
                %y0_a=-0.5
                pstODEsolve[algebraicOutputFormat]{y0_a}{t | x[0]}{-1}{1}{100}{-0.5}{t^2+x[0]^2-1}
                %y0_b=0.0
                pstODEsolve[algebraicOutputFormat]{y0_b}{t | x[0]}{-1}{1}{100}{0.0}{t^2+x[0]^2-1}
                %y0_c=0.5
                pstODEsolve[algebraicOutputFormat]{y0_c}{t | x[0]}{-1}{1}{100}{0.5}{t^2+x[0]^2-1}

                psset{arrows=-,linewidth=1pt}%
                listplot[linecolor=red ]{y0_a}
                listplot[linecolor=green]{y0_b}
                listplot[linecolor=blue ]{y0_c}
                end{pspicture}

                end{document}


                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 30 '15 at 8:18

























                answered Oct 18 '13 at 19:01









                HerbertHerbert

                273k24412725




                273k24412725






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to TeX - LaTeX 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.


                    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%2ftex.stackexchange.com%2fquestions%2f139114%2fdifferential-equation-direction-plot-with-pgfplots%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

                    How to change which sound is reproduced for terminal bell?

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents