# How to use output from previous line in Plot? [duplicate]

Suppose, I want to solve a equation and want to obtain it's first root. In this case I've used

In[1]=:Solve[b^2 + b*z + 1 == 0, b][[1]]


This gives

Out[2]={b -> 1/2 (-z - Sqrt[-4 + z^2])}


Now I want use this result directly in Plot command. My code for this is

In[3]:Plot[Out[2], {z, -1000, 1000}, PlotRange -> All]


But I'm not getting the plot. If I use

In[4]:Plot[1/2 (-z - Sqrt[-4 + z^2]), {z, -1000, 1000}, PlotRange -> All]


I'm getting the plot correctly. I guess in In[3], Out[2] contains b->, that's why it's unable to plot. How to handle this situation?

p.s. This is a prototype of my actual problem. I want to solve this in this way because my output is too large to copy and paste in the Plot command.

• Try Plot[%[[1, 2]], {z, -1000, 1000}, PlotRange -> All]! Taking second part of the Rule is the trick. You can also use Plot[Out[1][[1, 2]], {z, -1000, 1000}, PlotRange -> All]. – PlatoManiac May 28 '13 at 8:34
• @PlatoManiac. Thanks for suggestion. – Biswajit May 28 '13 at 10:46
• @PlatoManiac I would strongly advise against this suggestion (i.e., using % or Out). It makes repeating the results when you re-run your notebook dependent on the order of execution. When you are going to use the results of a calculation assign a variable to that result. – Sjoerd C. de Vries May 28 '13 at 15:24
• @SjoerdC.deVries Thx for pointing out the pitfall with Out or %. I though assumed the OP will understand this ordering issue himself while playing with the notebook and if not through the answers below. – PlatoManiac May 28 '13 at 20:40

sol = Solve[b^2 + b*z + 1 == 0, b][[1]];

and then plot using the strategy suggested in the Help file for Solve, which replaces the variable in the rule (in this case b) with the desired solution:
Plot[b /. sol, {z, -10, 10}, PlotRange -> All]