0
$\begingroup$

In Solve an equation with specific domain?

I asked how to write a code in Mathematica with one specific domain for one of its variables. Now I have a questions:

If two of the variables are from specific domain for which they have been taken correspondingly?

for example:

Solve[{z == 2 x + y && x > 0 && y > 0}, {x, y, z}, Integers] // Column

where $x\in\{1,2,5,6,9\}$, $y\in\{2,7,11,15,18\}$.

1) for the first case I mean it takes for {x,y}: {1,2}, {2,7}, {5,11}, {6,15}, {9,18}

2) for the second case it takes all $5^2$ cases, where 5 is the cardinal of the set.

P.S. for the second case I wrote the following

Clear[x, y, z]
set1 = {1,2,5,6,9};
set2 = {2,7,11,15,18};
Solve[{z == 2 x + y && x > 0 && y > 0 && Or @@ (Equal[x, #] & /@ set1) && 
Or @@ (Equal[y, #] & /@ set2)}, {x, y, z}, Integers] // Column

but for the first case?

thanks!

$\endgroup$
1
$\begingroup$

For this problem, Solve is not needed.

(sol1 = {#[[1]], #[[2]], 2 #[[1]] + #[[2]]} & /@
    Transpose[{{1, 2, 5, 6, 9}, {2, 7, 11, 15, 18}}]) // Column

enter image description here

(sol2 = (Outer[{#1, #2, 2 #1 + #2} &, {1, 2, 5, 6, 9}, {2, 7, 11, 15, 18}] // 
       Flatten[#, 1] &)) // Column

enter image description here

$\endgroup$
  • $\begingroup$ thanks for your answer, but does it work for more complicated equations? $\endgroup$ – asad Apr 21 '18 at 16:37

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.