Search code examples
functionlinear-algebramaple

Maple: Accessing the solutions of solve when solving for multiple functions


When I want to solve a set of linear equations for two functions, e.g.

solutions := solve({f(x)=x,g(x)=x},{f(x),g(x)});

what exactly can I do to work with the solutions as functions themselves in maple?

The only thing which I was able to do was

f_solution := x2 -> subs(x=x2, rhs(solutions[1]))

But that is ugly in many aspects. First, this trivial substitution x->x2 seems necessary, without it will not work. Second, the construct rhs(solutions[1]) is very bad, as it is not possible to control the order of the solutions. Consequently everytime I modify my equations, I would have to check manually, if the index [1] is still correct.

Is there a clean and standard way to extract the functions from the set?


Solution

  • solutions := solve({2*f(x)=sin(x),g(x)/3=cos(x)},{f(x),g(x)});
    
               /       1                        \ 
              { f(x) = - sin(x), g(x) = 3 cos(x) }
               \       2                        / 
    

    and now, with f_solution as an expression,

    f_solution := eval(f(x), solutions);
    
                            1       
                            - sin(x)
                            2       
    

    or with f_solution as a procedure,

    f_solution := unapply( eval(f(x), solutions), x);
    
                             1       
                        x -> - sin(x)
                             2