Ask Your Question

Finding solutions as numerical values rather than equations

asked 2015-09-03 09:29:52 -0500

DaveG gravatar image

The output of solve() returns equations. What's the easiest way to "unwrap" these to get numerical values? For instance, solve(x^2-4==0,x) returns [x==-2, x==2]. I'd like to define the associated list [-2,2].

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2015-09-03 12:45:28 -0500

jaia gravatar image

I would use:

[eq.rhs() for eq in sol]

The .rhs() method extracts the right-hand side of an equation.

edit flag offensive delete link more

answered 2015-09-03 10:15:19 -0500

kcrisman gravatar image

One of many, MANY possible solutions to this:

sage: solve(x^2-4==0,x, solution_dict=True)
[{x: -2}, {x: 2}]
sage: [ sol.values()[0] for sol in solve(x^2-4==0,x, solution_dict=True) ]
[-2, 2]

There isn't really an easy way to do this without programming, because the solution types can vary a lot. In the one-variable case this should be one reasonable way, though.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2015-09-03 09:29:52 -0500

Seen: 43 times

Last updated: Sep 03 '15