1
$\begingroup$

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: enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$
$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

enter image description here

Export["test.csv", table];

Import["test.csv"] // Grid

enter image description here

$\endgroup$
7
  • $\begingroup$ The posted code isn't getting solved for x. I am using Mathematica version 11. @Bob Hanlon $\endgroup$ Commented May 29, 2023 at 5:24
  • $\begingroup$ Could you please tell me how can I use it on version 11? @BobHanlon $\endgroup$ Commented May 29, 2023 at 5:48
  • $\begingroup$ 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 $\endgroup$ Commented May 29, 2023 at 17:34
  • $\begingroup$ Edited. Your range specification makes no sense in Mathematica. Presumably, you mean for the iterator to be {r, 20, 30, 0.01} $\endgroup$
    – Bob Hanlon
    Commented May 29, 2023 at 17:46
  • $\begingroup$ 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 $\endgroup$ Commented May 29, 2023 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.