Problem with solve command

  • Rene

    Rene - 2013-09-24

    I can´t use an output solution from solve command as a variable:

    (%i1) eq1:x+y=c;
    (%o1) y+x=c

    (%i2) x:solve([eq1], [x]);
    (%o2) [x=c-y]

    (%i3) Z:x+d;
    (%o3) [x+d=-y+d+c]

    the correct answer must be Z=-y+d+c, but maxima gives x+d=-y+d+c, could anyone help me?

  • Albrecht Mueller


    eq1: x+y=c;
    h: solve([eq1], [x]);
    x1: rhs(first(h));
    Z: x1+d;

    Reason: The solution you get is not a single value for x, but a list containing all the solutions, here assigned to the variable h. The list contains only one solution. You are interested in the right hand side of the first solution: rhs(first(h)). I assigned this to x1 in order to avoid confusion. If you add d to this you get what you want.

    What you did was adding d to the list of solutions which added d to both sides of any solution contained in the list.

  • Rene

    Rene - 2013-09-24

    Your solution is working, thank you very much.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks