Reputation: 155
I'm trying to solve an equation using Mathematica but I can't seem to get any actual answers.
Input:
Solve[(5*d) + (216*b) == 1, {d, b}, Integers]
Output:
{{d -> ConditionalExpression[173 + 216 C[1], C[1] \[Element] Integers],
b -> ConditionalExpression[-4 - 5 C[1], C[1] \[Element] Integers]}}
I want the output look something like this:
{b=123, d=456}
Is this possible to achieve?
Upvotes: 2
Views: 592
Reputation: 745
As others have pointed out, there is not one solution, but in fact a 1-parameter set of solutions (more precisely all the solutions are integer points on a line in (b,d) space).
Solve
gives you the parametric solution representing the infinite number of solutions.
A way to have a list of small modulus solutions of your system is to do the following
Get the definition of the solution from Solve
, renaming C[1] as n for convenience, and
explaining to Mathematica that n should be considered an integer.
az = Assuming[{n \[Element] Integers},
Simplify[{d, b} /.
Solve[(5*d) + (216*b) == 1, {d, b}, Integers] /. {C[1] -> n}]]
{{173 + 216 n, -4 - 5 n}}
Then generate solution by varying the parameter's value (We take only the first element of the solution expression, as Solve
always gives a list even if there is only one solution case).
Table[First[az], {n, -10, 10}]
{{-1987, 46}, {-1771, 41}, {-1555, 36}, {-1339, 31}, {-1123, 26}, {-907, 21}, {-691, 16}, {-475, 11}, {-259, 6}, {-43, 1}, {173, -4}, {389, -9}, {605, -14}, {821, -19}, {1037, -24}, {1253, -29}, {1469, -34}, {1685, -39}, {1901, -44}, {2117, -49}, {2333, -54}}
This gives you the points nearest to origin which are solutions to your problem. You can plot them with ListPlot
for instance.
Upvotes: 0
Reputation: 4209
Solve gives you the solution. If you want a solution, change that to FindInstance:
FindInstance[(5*d) + (216*b) == 1, {d, b}, Integers]
which would be:
{{d -> 173, b -> -4}}
If you'd like to bring some variety, you can get random solutions directly from solve:
Normal @ First @ Solve[(5*d) + (216*b) == 1, {d, b}, Integers] /.
C[1] -> RandomInteger[1000]
Upvotes: 1