Get values of solve variables as list in maple

Alec Jacobson

August 21, 2013

weblog/

I issue a solve command in maple like this one:

s:= solve({2*x1-x2=0,x1+x2=1},{x1,y2});

and I see as output:

s := {x1 = 1/3, x2 = 2/3}

I'd like to get the results as an ordered list. I've already carefully chosen my variable names so that they're ordered lexicographically, which is respected by the solve output. I tried to use convert, table, entries, indices to no avail. What I came up with is:

convert(map(rhs,s),list);

which produces:

[1/3, 2/3]

This can be easily dumped into matlab for processing.

Note: If you use square brackets in your solve:

s:= solve({2*x1-x2=0,x1+x2=1},[x1,x2]);

Then the map above will give you an error like this one:

Error, invalid input: rhs received [x1 = 1/3, x2 = 2/3], which is not valid for its 1st argument, expr

You need to get the first index of the solve output:

map(rhs,s[1]);