1
$\begingroup$

I just started using mathematica at school, so this is a newbie question. From a previous question i managed to get this:

ClearAll[x];
Reduce[505 == 500 + Mod[Mod[x, 66], 9], x, Integers]
(* Element[C[1], Integers] && (x == 5 + 66*C[1] || x == 14 + 66*C[1] || 
   x == 23 + 66*C[1] || x == 32 + 66*C[1] || x == 41 + 66*C[1] || 
   x == 50 + 66*C[1] || x == 59 + 66*C[1]) *)

I know that the answer that i am looking for is x=5,000 But if i give this command:

 FindInstance[
 C[1] ∈ 
   Integers && (x == 5 + 66 C[1] || x == 14 + 66 C[1] || 
    x == 23 + 66 C[1] || x == 32 + 66 C[1] || x == 41 + 66 C[1] || 
    x == 50 + 66 C[1] || x == 59 + 66 C[1]), {x}, 10]

i get the results:

{{x -> 28157}, {x -> -27112}, {x -> 18353}, {x -> -8275}, {x -> 
   3644}, {x -> 4613}, {x -> 32957}, {x -> -24415}, {x -> -21004}, {x -> 2342}}

Where is my x=5000 solution? How can i tell mathematica to give me only the solutions for lets say x>0 && x<10000 ? Is this possible?

$\endgroup$
2
  • $\begingroup$ FindInstance[ C[1] \[Element] Integers && (x == 5 + 66 C[1] || x == 14 + 66 C[1] || x == 23 + 66 C[1] || x == 32 + 66 C[1] || x == 41 + 66 C[1] || x == 50 + 66 C[1] || x == 59 + 66 C[1]) && 4000 < x < 6000, {x, C[1]}]? $\endgroup$ – Feyre Feb 7 '17 at 20:18
  • $\begingroup$ FindInstance[ C[1] [Element] Integers && (x == 5 + 66 C[1] || x == 14 + 66 C[1] || x == 23 + 66 C[1] || x == 32 + 66 C[1] || x == 41 + 66 C[1] || x == 50 + 66 C[1] || x == 59 + 66 C[1]) && 0 < x < 6000, {x, C[1]}, 20] Why is not showing my 5000 solution!?!? $\endgroup$ – Ray Feb 7 '17 at 20:26
1
$\begingroup$

If you're only interested in results in a certain range, you can try using Solve instead, and adding the condition to the expression, like so:

ClearAll[sol, vals, x];
sol = Solve[505 == 500 + Mod[Mod[x, 66], 9] && 0 < x < 10000, x, Integers];

I'm suppressing output because there's a lot of it!

Length@sol
(* 1061 *)

Note that Solve returns solutions as rules. Here are the first five:

Take[sol, 5]
(* {{x -> 5}, {x -> 14}, {x -> 23}, {x -> 32}, {x -> 41}} *)

We can get the list of values using ReplaceAll:

vals = x /. sol;
Take[vals, 5]
(* {5, 14, 23, 32, 41} *)

We can check to make sure that $ 5000 $ is indeed a solution:

MemberQ[vals, 5000]
(* True *)
$\endgroup$
1
  • $\begingroup$ Pillsy, thanks...Again!!! $\endgroup$ – Ray Feb 7 '17 at 20:39

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.