Menu ▾ ▴

#4480 Maxima differential equations

None
not-a-bug
nobody
5
2025-02-03
2025-01-31
No

Problems with diff equations as follows:
Problem 1
eq: 'diff(y(x), x) = y(x) - x^2 + 1;
sol: ode2(eq, y,x);
ysol(x) := rhs(sol);
wxplot2d(ysol(x), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title, "Solution of the Differential Equation"]);
(eq) 'diff(y(x),x,1)=y(x)-x^2+1(sol) 'diff(y(x),x,1)=y(x)-x^2+1
"not a proper differential equation"(sol) false ysol(x):=rhs(sol) false
Problem 2
eq: 'diff(y(x), x) = y(x) - x^2 + 1;
sol: desolve(eq, y);
ysol(x) := rhs(sol);
wxplot2d(ysol(x), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title, "Solution of the Differential Equation"]);
(eq) 'diff(y(x),x,1)=y(x)-x^2+1

desolve(<eqn>,<depvar>): dependent variable <depvar> cannot be a mapatom, found: y</depvar></depvar></eqn>

-- an error. To debug this try: debugmode(true);

Related

Bugs: #4480

Discussion

  • Jaime E. Villate

    This is not a bug but a wrong use of program ode2.
    You should do something as the following:

    (%i1) eq: 'diff(y, x) = y - x^2 + 1;
                                    dy        2
    (%o1)                           ── = y - x  + 1
                                    dx
    (%i2) gsol: ode2(eq, y,x);
                               2              - x     - x         x
    (%o2)           y = (- (- x  - 2 x - 2) %e    - %e    + %c) %e
    (%i3) psol: ic1(gsol,x=0,y=1);
                                        2
    (%o3)                          y = x  + 2 x + 1
    (%i4) ysol(x) := rhs(psol);
    (%o4)                        ysol(x) := rhs(psol)
    (%i5) plot2d(ysol(x), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title, "Solution of the Differential Equation"]);
    

    Notice that ode2 expects and equation with variables such as x and y, and not x and y(x). The solution given by ode2 is a general solution, which cannot be plotted because it has an unknown integration constant %c. You can plot a particular solution (psol above), which can be obtained by giving initial conditions with the program ic1. Please read the documentation for ode2.

     
  • Jaime E. Villate

    And in problem 2, desolve should be used as:

    desolve(eq, y(x));
    

    And not as you did. Both ode2 and desolve give you error messages in the examples you showed. You should not proceed to try to see a plot after such error messages. Also, the result of desolve will be a general solution, with an unknown variable, which cannot be plotted. To get a particular solution (which can be plotted) you have to use atvalue, in the case of desolve.

     
  • Stavros Macrakis

    • status: open --> not-a-bug
     
    • Allan James Payne

      Query
      (%i4) eq: 'diff(y(x), x) = y(x) - x^2 + 1;
      sol: desolve(eq, y(x));
      atvalue(y(x),x=0,1);
      wxplot2d(y, [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title, "Solution
      of the Differential Equation"]
      );
      wxplot2d(y(x), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title,
      "Solution of the Differential Equation"]
      );
      (eq) 'diff(y(x),x,1)=y(x)-x^2+1

      (sol) y(x)=(y(0)-1)%e^x+x^2+2x+1

      (%o3) 1

      plot2d: unknown function: y

      -- an error. To debug this try: debugmode(true);

      On Fri, Jan 31, 2025 at 7:04 PM Stavros Macrakis macrakis@users.sourceforge.net wrote:

      • status: open --> not-a-bug

      [bugs:#4480] https://sourceforge.net/p/maxima/bugs/4480/ Maxima
      differential equations

      Status: not-a-bug
      Group: None
      Labels: diff eqs general
      Created: Fri Jan 31, 2025 05:35 PM UTC by Allan James Payne
      Last Updated: Fri Jan 31, 2025 06:36 PM UTC
      Owner: nobody

      Problems with diff equations as follows:
      Problem 1
      eq: 'diff(y(x), x) = y(x) - x^2 + 1;
      sol: ode2(eq, y,x);
      ysol(x) := rhs(sol);
      wxplot2d(ysol(x), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title,
      "Solution of the Differential Equation"]
      );
      (eq) 'diff(y(x),x,1)=y(x)-x^2+1(sol) 'diff(y(x),x,1)=y(x)-x^2+1
      "not a proper differential equation"(sol) false ysol(x):=rhs(sol) false
      Problem 2
      eq: 'diff(y(x), x) = y(x) - x^2 + 1;
      sol: desolve(eq, y);
      ysol(x) := rhs(sol);
      wxplot2d(ysol(x), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title,
      "Solution of the Differential Equation"]
      );
      (eq) 'diff(y(x),x,1)=y(x)-x^2+1

      desolve(<eqn>,<depvar>): dependent variable <depvar> cannot be a mapatom,
      found: y</depvar></depvar></eqn>

      -- an error. To debug this try: debugmode(true);

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/maxima/bugs/4480/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #4480

      • Raymond Toy

        Raymond Toy - 2025-02-03

        I don't work with desolve very much, but I think you did things in the wrong order. And you misunderstand what desolve returns.

        This works a bit better in getting a solution:

        (%i10) atvalue(y(x),x=0,1);
        (%o10)                                 1
        (%i11) sol: desolve(eq, y(x));
                                              2
        (%o11)                        y(x) = x  + 2 x + 1
        (%i12) plot2d(rhs(sol), [x,-5,5]);
        

        In any case, bug reports are not for help. Please ask on the maxima mailing list for help.

         
      • Jaime E. Villate

        On 03/02/25 16:50, Allan James Payne wrote:

        Query
        (%i4) eq: 'diff(y(x), x) = y(x) - x^2 + 1;
        sol: desolve(eq, y(x));
        atvalue(y(x),x=0,1);
        wxplot2d(y, [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title, "Solution
        of the Differential Equation"]
        );
        wxplot2d(y(x), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title,
        "Solution of the Differential Equation"]
        );
        (eq) 'diff(y(x),x,1)=y(x)-x^2+1

        (sol) y(x)=(y(0)-1)%e^x+x^2+2x+1

        (%o3) 1

        plot2d: unknown function: y

        -- an error. To debug this try: debugmode(true);

        Hello,

        I don't know how you are using Maxima, but what we are all used to doing
        is to enter a command, look at its output to see if it works correctly
        and gives a result that we expected and only then continue to do the
        following part. In your case, I get the following:

        (%i1) eq: 'diff(y(x), x) = y(x) - x^2 + 1;
                                 d                   2
        (%o1)                    ── (y(x)) = y(x) - x  + 1
                                 dx
        (%i2) sol: desolve(eq, y(x));
                                               x    2
        (%o2)              y(x) = (y(0) - 1) %e  + x  + 2 x + 1
        (%i3) atvalue(y(x),x=0,1);
        (%o3)                                1

        %o2 shows an equation, not the definition of a function. And %i3 didn't
        produce any function either (that means that command was not used as it
        should be); the result "1" is unexpected. You cannot try to plot y(x)
        because at this point you have not defined any function y(x). You could
        try to plot the right-hand side of %o2, an expression, but plot2d will
        complain that the value of y(0) is unknown (that's what atvalue should
        have defined if it had been correct and used before desolve).

        However, you could still proceed if you substitute a value for y(0) and
        then do the plot:

        (%i4) plot2d (subst(y(0)=1,rhs(%o2)), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"]);

        The good thing is that you have now discovered the right place where to
        ask for help :)

        Regards,

        Jaime

         
        • Allan James Payne

          Hi Jamie
          Thanks for your comments. I make up a cell as a set of commands which I
          develop as I go along.
          I had expected the desolve to give a general solution and the atvalue after
          the desolve to make it a particular solution so that I can graph the
          function. I made a simple test to show the problem. I understand the fact
          that the plot should have a particular solution.
          I think that there is a problem witth atvalue which I would have thought
          provided a value for y(0). and there is a bug.
          Thank you for your help.
          Rgds Allan Payne

          On Mon, Feb 3, 2025 at 6:31 PM Jaime E. Villate villate@users.sourceforge.net wrote:

          On 03/02/25 16:50, Allan James Payne wrote:

          Query
          (%i4) eq: 'diff(y(x), x) = y(x) - x^2 + 1;
          sol: desolve(eq, y(x));
          atvalue(y(x),x=0,1);
          wxplot2d(y, [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title, "Solution
          of the Differential Equation"]
          );
          wxplot2d(y(x), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title,
          "Solution of the Differential Equation"]
          );
          (eq) 'diff(y(x),x,1)=y(x)-x^2+1

          (sol) y(x)=(y(0)-1)%e^x+x^2+2x+1

          (%o3) 1

          plot2d: unknown function: y

          -- an error. To debug this try: debugmode(true);

          Hello,

          I don't know how you are using Maxima, but what we are all used to doing
          is to enter a command, look at its output to see if it works correctly
          and gives a result that we expected and only then continue to do the
          following part. In your case, I get the following:

          (%i1) eq: 'diff(y(x), x) = y(x) - x^2 + 1;
          d 2
          (%o1) ── (y(x)) = y(x) - x + 1
          dx
          (%i2) sol: desolve(eq, y(x));
          x 2
          (%o2) y(x) = (y(0) - 1) %e + x + 2 x + 1
          (%i3) atvalue(y(x),x=0,1);
          (%o3) 1

          %o2 shows an equation, not the definition of a function. And %i3 didn't
          produce any function either (that means that command was not used as it
          should be); the result "1" is unexpected. You cannot try to plot y(x)
          because at this point you have not defined any function y(x). You could
          try to plot the right-hand side of %o2, an expression, but plot2d will
          complain that the value of y(0) is unknown (that's what atvalue should
          have defined if it had been correct and used before desolve).

          However, you could still proceed if you substitute a value for y(0) and
          then do the plot:

          (%i4) plot2d (subst(y(0)=1,rhs(%o2)), [x, -5, 5], [ylabel, "y(x)"], [xlabel,
          "x"]
          );

          The good thing is that you have now discovered the right place where to
          ask for help :)

          Regards,

          Jaime

          [bugs:#4480] https://sourceforge.net/p/maxima/bugs/4480/ Maxima
          differential equations

          Status: not-a-bug
          Group: None
          Labels: diff eqs general
          Created: Fri Jan 31, 2025 05:35 PM UTC by Allan James Payne
          Last Updated: Mon Feb 03, 2025 05:19 PM UTC
          Owner: nobody

          Problems with diff equations as follows:
          Problem 1
          eq: 'diff(y(x), x) = y(x) - x^2 + 1;
          sol: ode2(eq, y,x);
          ysol(x) := rhs(sol);
          wxplot2d(ysol(x), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title,
          "Solution of the Differential Equation"]
          );
          (eq) 'diff(y(x),x,1)=y(x)-x^2+1(sol) 'diff(y(x),x,1)=y(x)-x^2+1
          "not a proper differential equation"(sol) false ysol(x):=rhs(sol) false
          Problem 2
          eq: 'diff(y(x), x) = y(x) - x^2 + 1;
          sol: desolve(eq, y);
          ysol(x) := rhs(sol);
          wxplot2d(ysol(x), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title,
          "Solution of the Differential Equation"]
          );
          (eq) 'diff(y(x),x,1)=y(x)-x^2+1

          desolve(<eqn>,<depvar>): dependent variable <depvar> cannot be a mapatom,
          found: y</depvar></depvar></eqn>

          -- an error. To debug this try: debugmode(true);

          Sent from sourceforge.net because you indicated interest in
          https://sourceforge.net/p/maxima/bugs/4480/

          To unsubscribe from further messages, please visit
          https://sourceforge.net/auth/subscriptions/

           

          Related

          Bugs: #4480

          • Jaime E. Villate

            On 03/02/25 20:33, Allan James Payne wrote:

            I think that there is a problem witth atvalue which I would have thought
            provided a value for y(0). and there is a bug.

            No that is not a bug. It is well documented that atvalue must be used
            before desolve, because desolve uses the Laplace transform, so the
            initial condition must be given before desolve calls "laplace".

            That is different from the behavior of ode2 and ic1, because in order
            for ic1 to evaluate the value of the integration constant, ode2 must
            first do its job giving a result with an integration constant %c.

            You should take a look at the examples in:

            https://maxima.sourceforge.io/docs/manual/maxima_111.html

            Finally, I was wrong when I said that "you have found the right place to
            ask for help". You should be asking this kind of questions in the list
            maxima-discuss (see: https:///maxima.sourceforge.io/maximalist.html) and
            not here.

            Even the experts who have worked with Maxima for several decades usually
            write in that list when they think they have found a bug, before opening
            a bug report.

            Regards,

            Jaime

             
            • Allan James Payne

              Hi Jamie
              Thanks for your email. I will go back to sleep. I am sorry to have caused
              any trouble .
              Rgds Allan Payne

              On Mon, Feb 3, 2025 at 8:47 PM Jaime E. Villate villate@users.sourceforge.net wrote:

              On 03/02/25 20:33, Allan James Payne wrote:

              I think that there is a problem witth atvalue which I would have thought
              provided a value for y(0). and there is a bug.

              No that is not a bug. It is well documented that atvalue must be used
              before desolve, because desolve uses the Laplace transform, so the
              initial condition must be given before desolve calls "laplace".

              That is different from the behavior of ode2 and ic1, because in order
              for ic1 to evaluate the value of the integration constant, ode2 must
              first do its job giving a result with an integration constant %c.

              You should take a look at the examples in:

              https://maxima.sourceforge.io/docs/manual/maxima_111.html

              Finally, I was wrong when I said that "you have found the right place to
              ask for help". You should be asking this kind of questions in the list
              maxima-discuss (see: https:///maxima.sourceforge.io/maximalist.html
              https://sourceforge.net/maxima.sourceforge.io/maximalist.html) and
              not here.

              Even the experts who have worked with Maxima for several decades usually
              write in that list when they think they have found a bug, before opening
              a bug report.

              Regards,

              Jaime

              [bugs:#4480] https://sourceforge.net/p/maxima/bugs/4480/ Maxima
              differential equations

              Status: not-a-bug
              Group: None
              Labels: diff eqs general
              Created: Fri Jan 31, 2025 05:35 PM UTC by Allan James Payne
              Last Updated: Mon Feb 03, 2025 05:19 PM UTC
              Owner: nobody

              Problems with diff equations as follows:
              Problem 1
              eq: 'diff(y(x), x) = y(x) - x^2 + 1;
              sol: ode2(eq, y,x);
              ysol(x) := rhs(sol);
              wxplot2d(ysol(x), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title,
              "Solution of the Differential Equation"]
              );
              (eq) 'diff(y(x),x,1)=y(x)-x^2+1(sol) 'diff(y(x),x,1)=y(x)-x^2+1
              "not a proper differential equation"(sol) false ysol(x):=rhs(sol) false
              Problem 2
              eq: 'diff(y(x), x) = y(x) - x^2 + 1;
              sol: desolve(eq, y);
              ysol(x) := rhs(sol);
              wxplot2d(ysol(x), [x, -5, 5], [ylabel, "y(x)"], [xlabel, "x"], [title,
              "Solution of the Differential Equation"]
              );
              (eq) 'diff(y(x),x,1)=y(x)-x^2+1

              desolve(<eqn>,<depvar>): dependent variable <depvar> cannot be a mapatom,
              found: y</depvar></depvar></eqn>

              -- an error. To debug this try: debugmode(true);

              Sent from sourceforge.net because you indicated interest in
              https://sourceforge.net/p/maxima/bugs/4480/

              To unsubscribe from further messages, please visit
              https://sourceforge.net/auth/subscriptions/

               

              Related

              Bugs: #4480

              • Raymond Toy

                Raymond Toy - 2025-02-03

                You have not caused trouble. If you have further questions, please use the mailing list. There are lots more people reading that than bug reports and you'll get more help there. We welcome new users to join the list and ask questions!

                 
                • Jaime E. Villate

                  On 03/02/25 21:39, Raymond Toy wrote:

                  You have not caused trouble. If you have further questions, please use the mailing list. There are lots more people reading that than bug reports and you'll get more help there. We welcome new users to join the list and ask questions!

                  Exactly! I was actually happy to talk about solving differential
                  equations using ode2 and desolve. I also run into similar problems as
                  you did when I started using Maxima 30 years ago. Then I taught a course
                  on differential equations using Maxima for several years, but I haven't
                  had the chance to teach that course again in the last few years, so any
                  opportunity to talk about the subject is always welcome.

                  Jaime

                   

Log in to post a comment.