Opened 8 years ago
Last modified 5 years ago
#10213 new defect
Make solution_dict the default output for solve
Reported by: | olazo | Owned by: | olazo |
---|---|---|---|
Priority: | minor | Milestone: | sage-6.4 |
Component: | symbolics | Keywords: | solve, solution_dict |
Cc: | Merged in: | ||
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
This is what mathematica does, and a much easier way to work with the results than getting an equation.
This has been discussed in:
http://groups.google.com/group/sage-devel/browse_thread/thread/93a9897c35ea0d80
Change History (8)
comment:1 Changed 8 years ago by
comment:2 Changed 8 years ago by
Also, it possibly breaks a lot of existing code. There should be some thought put in before this happens.
comment:3 Changed 8 years ago by
+1 to thinking. I think it probably warrants a different function name than solve, or maybe just a different syntax for calling solve.
I don't think it will confuse people who haven't seen a dict. The output would look like this:
[{x: 3, y: 4}, {x: 1, y: 5}]
which I think is very understandable.
comment:4 Changed 7 years ago by
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 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]]
comment:5 Changed 6 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:6 Changed 5 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:7 Changed 5 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:8 Changed 5 years ago by
- Milestone changed from sage-6.3 to sage-6.4
Question: will this confused people who have never seen a dict before? After all, that is a large part of who is using this functionality (based on sage-support requests).