# defining output Solve

I'm just starting with Mathematica and I was having a small question: How can you "define" the outcome of a "Solve" in Mathematica? Here is an example from mathematica:

Solve[a x^2 + b x + c == 0, x]


{{x -> (-b - Sqrt[b^2 - 4 a c])/(2 a)}, {x -> (-b + Sqrt[b^2 - 4 a c])/(2 a)}}

I would like to call

x1:= (-b - Sqrt[b^2 - 4 a c])/(2 a)

x2:=(-b + Sqrt[b^2 - 4 a c])/(2 a)

And then make a list {x1, x2} How can you let this happen automatically, because with 2 values it's quite easy but I would like to solve a linear equation with many more solutions.

• x /. Solve[a x^2 + b x + c == 0, x] – eldo Nov 11 '15 at 10:02
• {x1, x2} = x /. Solve[a x^2 + b x + c == 0, x] – Sjoerd C. de Vries Nov 11 '15 at 10:24

You can have a list like so:

sol = Solve[a x^2 + b x + c == 0, x]


$$\left\{\left\{x\to \frac{-\sqrt{b^2-4 a c}-b}{2 a}\right\},\left\{x\to \frac{\sqrt{b^2-4 a c}-b}{2 a}\right\}\right\}$$

see ReplaceAll for details

list = x /. sol


$$\left\{\frac{-\sqrt{b^2-4 a c}-b}{2 a},\frac{\sqrt{b^2-4 a c}-b}{2 a}\right\}$$

an use parts of your list, see Part:

list[]


(-b - Sqrt[b^2 - 4 a c])/(2 a)

i.e. will be your x1

list[]


(-b + Sqrt[b^2 - 4 a c])/(2 a)

i.e. will be your x2

Assuming:

a = Table[1, {i, 5}]; b = Table[i, {i, -4, 0}]; c = Table[i, {i, 1, 5}];


with list[] and list[] respectively you'll generate

$$\left\{\frac{1}{2} \left(4-2 \sqrt{3}\right),1,\frac{1}{2} \left(2-2 i \sqrt{2}\right),\frac{1}{2} \left(1-i \sqrt{15}\right),-i \sqrt{5}\right\}$$

$$\left\{\frac{1}{2} \left(4+2 \sqrt{3}\right),2,\frac{1}{2} \left(2+2 i \sqrt{2}\right),\frac{1}{2} \left(1+i \sqrt{15}\right),i \sqrt{5}\right\}$$