2
$\begingroup$

My goal is to generate matrices, on which I will put different constraints in Reduce funcion, e.g.:

M = {{a, b}, {c, d}}
Reduce[M == {{1,2},{3,4}}, {a,b,c,d}]

I want to create a function, that will generate a matrix of variables (of given size), which I could later use in such a case as the above one. So far I figured out only something like this:

TabGen[a_, n_] := Table[a <> ToString[i] <> ToString[j], {i, 1, n}, {j, 1, n}]

but when I used it in a similar case, as the first one:

A = TabGen["a", 2]
Reduce[A == {{1, 2}, {3, 4}}, {a11, a12, a21, a22}]

I got:

{{"a11", "a12"}, {"a21", "a22"}}
False

My gues is that this function creates a matrix of strings, which cannot be considered as variables and used later in Reduce. How could I solve this problem?

$\endgroup$
3
  • 1
    $\begingroup$ TabGen[a_, n_] := Table[Symbol[a <> ToString[i] <> ToString[j]], {i, 1, n}, {j, 1, n}] $\endgroup$ Apr 5, 2019 at 11:30
  • $\begingroup$ This works perfectly, thank you! $\endgroup$ Apr 5, 2019 at 11:41
  • $\begingroup$ You're welcome. $\endgroup$ Apr 5, 2019 at 11:42

1 Answer 1

1
$\begingroup$

Consider using indexed variables instead:

A = Array[a, {2, 2}];
Reduce[A == {{1, 2}, {3, 4}}, Flatten@A]

a[1,1] == 1 && a[1,2] == 2 && a[2,1] == 3 && a[2,2] == 4

$\endgroup$

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.