3
$\begingroup$

Let $$x+5=z\tag1$$

1. How can i obtain all the values of $0<x<10$ which don't satisfy the given relation. Edit: of course $x$ and $z$ are positive integers.

2. What command should i use to find the first instance and to stop the calculations.

How many ways exist in mathematica to sort out only numbers which don't satisty a given relation.

This may appear straighforward for most of you, but thank you so much for your kind welcome.

$\endgroup$
2
  • 2
    $\begingroup$ What does $y$ have to do with anything? $\endgroup$ Nov 11, 2023 at 21:00
  • $\begingroup$ Thank you. Edited. It was a typo error $\endgroup$
    – Mathix
    Nov 12, 2023 at 14:36

1 Answer 1

5
$\begingroup$

Perhaps

FindInstance[! (x + 5 == z) && 0 < x < 10, {x, z}, Reals, 10]

(*
{{x -> 638/101, z -> -1}, {x -> 919/101, z -> 106}, 
{x -> 134/101,z -> -36}, {x -> 816/101, z -> -33}, 
{x -> 950/101,z -> 103}, {x -> 642/101, z -> -52},
{x -> 744/101,z -> 79}, {x -> 709/101, z -> 88}, 
{x -> 769/101,z -> -27}, {x -> 713/101, z -> 51}}
*)

addendum

Only integer solution

sol=FindInstance[! (x + 5 == z) && 0 <= x <= 10, {x, z}, Integers,10]
SortBy[sol, (x /. # &)]
(*{{x -> 1, z -> 277}, {x -> 3, z -> -981}, 
{x -> 3,z -> -490}, {x -> 3, z -> 703}, 
{x -> 4, z -> 694}, {x -> 6,z -> 10}, {x -> 6, z -> 386}, 
{x -> 7, z -> -618}, {x -> 8,z -> 14}, {x -> 8, z -> 198}}*)
$\endgroup$
8
  • $\begingroup$ Thank you so much. Maybe should i precise that $x$ and $z$ are positive integers. And i am looking for the smallest vallue of $x$ for the instance. $\endgroup$
    – Mathix
    Nov 11, 2023 at 16:24
  • 1
    $\begingroup$ Try sol=FindInstance[! (x + 5 == z) && 0 <= x <= 10, {x, z}, Integers, 10] and select the instance with smallest x SortBy[sol, (x /. # &)] $\endgroup$ Nov 11, 2023 at 16:31
  • $\begingroup$ Thank you so much. $\endgroup$
    – Mathix
    Nov 11, 2023 at 16:34
  • 1
    $\begingroup$ You are welcome! $\endgroup$ Nov 11, 2023 at 16:35
  • 1
    $\begingroup$ @DavidG.Stork I gave the right answer in my comment (UlrichNeumann has noticed it after all ;-)) and forgot to modify my answer. Done! $\endgroup$ Nov 12, 2023 at 15:18

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.