# How to use the second solution of an equation?

asked 2014-09-10 15:40:28 +0100

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi, I'm new to Sage and have the following question:

After solving an equation, Sage gives me two possible solutions:

sage: solve((vMax-v0) == (DeltaV11+DeltaV13), aMax)

[aMax == -sqrt(1/2a0^2 - j(v0 + j(vMax), aMax = sqrt(1/2a0^2 - j(v0 + j(vMax)]

For the further calculations, I have to use the second one. How can I do that?

Thank you for your help!

edit retag close merge delete

Sort by ยป oldest newest most voted

solve returns a list of equations (or a list of lists of equations)

Assign to a name (for example sol)

sol = solve(x^2 == 4 , x)
sol

[x == -2, x == 2]

Access to the equations in the list

First, second, last:

sol[0] ; sol[1] ; sol[-1]

x == -2
x == 2
x == 2

Access to the right hand side of the second equation:

sol[1].rhs()
more

It's a Python list:

sage: sol=solve(x^2==1,x)
sage: sol
[x == -1, x == 1]
sage: sol[0]
x == -1
sage: sol[1]
x == 1
more