# Export the real roots of an equation

I wish to find the roots of y (with only its real part) for different values of r in range 1(0.01)30. I have tried the following:

b = 2.6666;
Pr = 10;
y = Roots[x^3 + x^2 (1 + b + Pr) + x (b + b (r - 1) + Pr*b) + 2*Pr*b (r - 1) == 0, x];
q1 = y /. {r -> {0}}
q2 = y /. {r -> {0.01}}
q3 = y /. {r -> {0.02}}
q4 = y /. {r -> {0.03}}


Is there a neater way to do this? Also, I want to export these roots to an excel sheet as shown here:

\$Version

"13.2.1 for Mac OS X ARM (64-bit) (January 27, 2023)"

Clear["Global*"]

b = 2.6666;
Pr = 10;


EDIT 2: Modified to return real part of roots rather than real roots.

(table = Prepend[
Table[{r, Sequence @@
Re[SolveValues[
x^3 + x^2 (1 + b + Pr) + x (b + b (r - 1) + Pr*b) +
2*Pr*b (r - 1) == 0, x]]},
{r, 0, 0.03, 0.01}],
{"r", "x1", "x2", "x3"}]) // Grid


EDIT: Or, for earlier versions without SolveValues, use

(table =
Prepend[Table[{r,
Sequence @@ Re[(x /.
Solve[x^3 + x^2 (1 + b + Pr) + x (b + b (r - 1) + Pr*b) +
2*Pr*b (r - 1) == 0, x])]}, {r, 0, 0.03,
0.01}], {"r", "x1", "x2", "x3"}]) // Grid


Export["test.csv", table];

Import["test.csv"] // Grid


• The posted code isn't getting solved for x. I am using Mathematica version 11. @Bob Hanlon May 29, 2023 at 5:24
• Could you please tell me how can I use it on version 11? @BobHanlon May 29, 2023 at 5:48
• Something is not right. For example, in range r=20(0.01)30, only a single root is displayed. I want to get all the three roots but with their real parts. @BobHanlon May 29, 2023 at 17:34
• Edited. Your range specification makes no sense in Mathematica. Presumably, you mean for the iterator to be {r, 20, 30, 0.01}` May 29, 2023 at 17:46
• Oh Yes I want the iterator to be {r, 20, 30, 0.01}. However, after using the edited code, there is still no difference in the output . @BobHanlon May 29, 2023 at 17:54