Advice: Picking out members of a solution set

When Maple's various "solve" commands (including solve , dsolve , fsolve , isolve , msolve and rsolve ) return the values of more than one variable or function, they generally do so in the form of a set of equations, e.g. {x = 5, y = 4} . As with any set, the order in which these occur is unpredictable. In particular, if you save your worksheet and reload it in another session, the answer that was {x = 5, y = 4} the first time may well be {y = 4, x = 5} the next time. Therefore it is dangerous to try to extract the parts of a solution in a way that depends on the order in which they are presented in the set. Instead, the recommended method is to use the subs command.

In the case of the numerical solution of a differential equation ( dsolve(...,numeric) ), the default is to return a procedure whose output will be a list of values of the dependent and independent variables. If the dependent variables are specified as a list rather than a set, this list will have the independent variable followed by the dependent variables in the same order as in the list. Note that without the numeric option, the dependent variables must be a set, not a list. Still, the most convenient method is to use subs to extract the value of the variable you want. On the other hand, dsolve(..., numeric, output=listprocedure) returns a list from which subs extracts a procedure to calculate the value of each variable. Alternatively, dsolve(..., numeric, values=...) returns a matrix with the values of the dependent variables at each of an array of values of the independent variable.


> solution:= solve({ x + y = 9, x - y = 1},{x,y});

solution := {y = 4, x = 5}

> xvalue:= subs(solution,x);

xvalue := 5

> xy:= subs(solution,[x,y]);

xy := [5, 4]

> q:= subs(solution, x^2 + y^2);

q := 41

> de:= {D(x)(t)=x(t)+y(t), D(y)(t)=y(t), x(0)=1, y(0)=1}:

> desol1:= dsolve(de, {x(t),y(t)});

desol1 := {y(t) = exp(t), x(t) = exp(t)*(t+1)}

> x1:= unapply(subs(desol1,x(t)), t);

x1 := proc (t) options operator, arrow; exp(t)*(t+1...

> desol2:= dsolve(de, [x(t),y(t)],numeric);

desol2 := proc (rkf45_x) local i, rkf45_s, outpoint...

> desol2(1);

[t = 1, x(t) = 5.436563629797723, y(t) = 2.71828182...

> subs(%, x(t));


> desol3:=dsolve(de,[x(t),y(t)],numeric,

desol3 := [t = proc (t) option `Copyright (c) 1993 ...
desol3 := [t = proc (t) option `Copyright (c) 1993 ...
desol3 := [t = proc (t) option `Copyright (c) 1993 ...

> x3:= subs(desol3,x(t));

x3 := proc (t) local rkf45_s, outpoint, r1, r2; glo...

> x3(1);


> desol4:= dsolve(de,[x(t),y(t)],numeric,

desol4 := matrix([[vector([t, x(t), y(t)])], [matri...

See also: subs , solve , dsolve , dsolve/numeric , fsolve , isolve , msolve , rsolve

Maple Advisor Database, R. Israel 1997