Message Boards Message Boards

0
|
1267 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Find values of variables when Equation is true

Posted 4 years ago

I have en equation, and it is in a table, and according to the documentation it should just print out the values of my variables but the equation is only true sometimes, when i, j, k, and l have certain values, here is my code.

Table[(i)^3 + (j)^2 + (k)^3 + (l)^3 == 0, {i, 0, 10, 1}, {j, 0, 10, 
   1}, {k, -10, 0, 1}, {l, -10, 0, 1}];
N[%]

enter image description here

How can I get Mathematica to print out the values for i, j, k, and l for the statement is true?

POSTED BY: Ellen Alcorn
2 Replies
Posted 4 years ago

Thanks! Putting these results in an arravy would then simply be a matter of the following?

data=Table[...
POSTED BY: Ellen Alcorn
Posted 4 years ago

Hi Ellen,

One way to do it

Table[If[(i)^3 + (j)^2 + (k)^3 + (l)^3 == 0, {i, j, k, l}, Nothing], 
     {i, 0, 10, 1}, {j, 0, 10, 1}, {k, -10, 0, 1}, {l, -10, 0, 1}] //
  Flatten[#, 3] & //
  Select[Length@# > 0 &]

{{0, 0, 0, 0}, {0, 1, -1, 0}, {0, 1, 0, -1}, {0, 3, -2, -1}, {0, 3, -1, -2}, {0, 4, -2, -2}, {0, 8, -4, 0}, {0, 8, 0, -4}, {1, 0, -1, 0}, {1, 0, 0, -1}, {1, 1, -1, -1}, {1, 8, -4, -1}, {1, 8, -1, -4}, {2, 0, -2, 0}, {2, 0, 0, -2}, {2, 1, -2, -1}, {2, 1, -1, -2}, {2, 8, -4, -2}, {2, 8, -2, -4}, {3, 0, -3, 0}, {3, 0, 0, -3}, {3, 1, -3, -1}, {3, 1, -1, -3}, {3, 8, -4, -3}, {3, 8, -3, -4}, {4, 0, -4, 0}, {4, 0, 0, -4}, {4, 1, -4, -1}, {4, 1, -1, -4}, {4, 8, -4, -4}, {5, 0, -5, 0}, {5, 0, 0, -5}, {5, 1, -5, -1}, {5, 1, -1, -5}, {5, 8, -5, -4}, {5, 8, -4, -5}, {6, 0, -6, 0}, {6, 0, 0, -6}, {6, 1, -6, -1}, {6, 1, -1, -6}, {6, 8, -6, -4}, {6, 8, -4, -6}, {7, 0, -7, 0}, {7, 0, 0, -7}, {7, 1, -7, -1}, {7, 1, -1, -7}, {7, 8, -7, -4}, {7, 8, -4, -7}, {8, 0, -8, 0}, {8, 0, 0, -8}, {8, 1, -8, -1}, {8, 1, -1, -8}, {8, 8, -8, -4}, {8, 8, -4, -8}, {9, 0, -9, 0}, {9, 0, 0, -9}, {9, 1, -9, -1}, {9, 1, -1, -9}, {9, 8, -9, -4}, {9, 8, -4, -9}, {10, 0, -10, 0}, {10, 0, 0, -10}, {10, 1, -10, -1}, {10, 1, -1, -10}, {10, 8, -10, -4}, {10, 8, -4, -10}}

You could also use Sow and Reap.

Last@Reap[
  Table[If[(i)^3 + (j)^2 + (k)^3 + (l)^3 == 0, 
     Sow[{i, j, k, l}, 1]], {i, 0, 10, 1}, {j, 0, 10, 1}, {k, -10, 0, 1}, {l, -10, 0, 1}];, 1]

Or NSolve

NSolve[(i)^3 + (j)^2 + (k)^3 + (l)^3 == 0 && i >= 0 && i <= 10 && 
  j >= 0 && j <= 10 && k >= -10 && k <= 0 && l >= -10 && l <= 0,
 {i, j, k, l},
 Integers]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract