2
$\begingroup$

I am trying to find all the solutions to a Diophantine equation (only integer valued solutions) using Solve[], however there are multiple and even many solutions sometimes.

How can I store these individual solutions as rows of a matrix?

When I apply the rules to the variables, and then display as table, or matrix, and then get the dimension of the resulting "table", it appears that it is just one long vector, and not a matrix as it appears.

For example: Solve[2/3-1/x-1/y-1/z==0 &&x>=1 &&y>=x &&z>=y,{x,y,z},Integers]. This produces 8 solutions of the form (x,y,z). So I would like each solution to be an individual row in an 8x3 matrix.

$\endgroup$
  • $\begingroup$ Solve[2/3 - 1/x - 1/y - 1/z == 0 && x >= 1 && y >= x && z >= y, {x, y, z}, Integers][[All, All, 2]], maybe? $\endgroup$ – user1066 Jul 19 '17 at 15:06
2
$\begingroup$
eq = 2/3 - 1/x - 1/y - 1/z == 0 && x >= 1 && y >= x && z >= y;
var = {x, y, z};
(mat = var /. Solve[eq, var, Integers]) // MatrixForm
Dimensions[mat]

$\left( \begin{array}{ccc} 2 & 7 & 42 \\ 2 & 8 & 24 \\ 2 & 9 & 18 \\ 2 & 10 & 15 \\ 2 & 12 & 12 \\ 3 & 4 & 12 \\ 3 & 6 & 6 \\ 4 & 4 & 6 \\ \end{array} \right)$
{8, 3}

$\endgroup$
  • $\begingroup$ I have done that, but when I go to store this as a matrix, it turns out to be a 1x24 matrix with just each row appended to each other. $\endgroup$ – Matthew Crawford Jul 19 '17 at 13:04
  • $\begingroup$ @MatthewCrawford The above code yields a 8x3 matrix. What code did you use? $\endgroup$ – Coolwater Jul 19 '17 at 13:07
  • $\begingroup$ Table3=({x,y,z}/. Solve[2/3-1/x-1/y-1/z==0 && x>=1 && y>=x && z>=y,{x,y,z},Integers])//MatrixForm Dimensions[Table3] $\endgroup$ – Matthew Crawford Jul 19 '17 at 13:13
  • $\begingroup$ You store a MatrixForm in Table3, because // MatrixForm has higher precedence than Table3 = . If you left click 3 times fast on "//" you can see how the code is parsed $\endgroup$ – Coolwater Jul 19 '17 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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