Ask Your Question

Finding solutions as numerical values rather than equations

asked 2015-09-03 16:29:52 +0200

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 19:45:28 +0200

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 17:15:19 +0200

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 16:29:52 +0200

Seen: 370 times

Last updated: Sep 03 '15