Skip to main content

replacement - Assign output of solve to variables



I have this input:


Solve[x^2 + 3 x + 2 == 0, x]

which gives this output:


{{x -> -2}, {x -> -1}}

I want the first x to be named x1 and the second x to be named x2 without having to copy the value and doing x1=-2 manually and x2=-1




Answer



{x1, x2} = x /. Solve[x^2 + 3 x + 2 == 0, x]


{-2, -1}

Comments