#10213: Make solution_dict the default output for solve
-------------------------+--------------------------------------------------
Reporter: olazo | Owner: olazo
Type: defect | Status: new
Priority: minor | Milestone: sage-4.7.2
Component: symbolics | Keywords: solve,solution_dict
Work_issues: | Upstream: N/A
Reviewer: | Author:
Merged: | Dependencies:
-------------------------+--------------------------------------------------
Comment(by kcrisman):
Here is an idea from Jeff Denny which is related.
{{{
def get_solns(eqtns,vars):
return map(lambda t: map(lambda x: x.rhs(), t),solve(eqtns,vars))
}}}
With examples [http://sage.maa.org/home/pub/91/ here]:
{{{
var('x,y,z')
(x, y, z)
Usual method for getting solutions out of the solve command
s=solve([x+y==1,-2*x+y==0],[x,y])
s
[[x == (1/3), y == (2/3)]]
s[0]
[x == (1/3), y == (2/3)]
s[0][0].rhs(),s[0][1].rhs()
(1/3, 2/3)
Another approach to get solutions out of the solve command
Produces a list of solutions (order corresponds to that of the variables
input into vars).
def get_solns(eqtns,vars):
return map(lambda t: map(lambda x: x.rhs(), t),solve(eqtns,vars))
get_solns([x^2+y==1,-2*x+y==0],[x,y])
[[-sqrt(2) - 1, -2*sqrt(2) - 2], [sqrt(2) - 1, 2*sqrt(2) - 2]]
get_solns([3*x+y+z==1,x+y==5,7*x^3-y+2*z==4],[x,y,z])
[[-0.725116922845 - 1.0718265843*I, 5.72511692285 + 1.0718265843*I,
-2.54976615431 + 2.14365316861*I], [-0.725116922845 +
1.0718265843*I, 5.72511692285 - 1.0718265843*I, -2.54976615431 -
2.14365316861*I], [1.45023380094, 3.54976619906, -6.90046760187]]
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10213#comment:4>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.