0
$\begingroup$

I am trying get a table of (x-a)*(x-b), where a > b. I tried

Table[{(x - a) (x - b)}, {a, 5}, {b, 5}]

If I used,

Table[{(x - a) (x - b)}, {a, 5}, {b, 5}, {a > b}]

I can not get the result. How can I get the correct result?

$\endgroup$
  • 2
    $\begingroup$ One way is Flatten@Table[{(x - a) (x - b)}, {b, 5}, {a, b+1, 5}] $\endgroup$ – Thies Heidecke Jul 4 at 1:21
  • $\begingroup$ @ThiesHeidecke Thank you very much. $\endgroup$ – minhthien_2016 Jul 4 at 1:56
  • $\begingroup$ @ThiesHeidecke How about (x-a)*(x-b)*(x-c), where a > b>c ? $\endgroup$ – minhthien_2016 Jul 14 at 2:48
  • 1
    $\begingroup$ You can always refer to earlier table variables to define the range start/end of all following variables, so the previous answer should generalize to the a,b,c case: Flatten@Table[{(x - a) (x - b) (x - c)}, {c, 5}, {b, c+1, 5}, {a, b+1, 5}]. $\endgroup$ – Thies Heidecke Jul 15 at 0:00
  • $\begingroup$ Thank you very much. $\endgroup$ – minhthien_2016 Jul 15 at 1:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.