3
$\begingroup$

I'm trying to use FindInstance to find examples of matrices that complete an expression. However, it seems like I need to specify atomics as my variables to the function. So, here's a really simple example of what I'm trying to do.

A simple test condition could be that my d-dimensional matrix lol should be the identity matrix on those d dimensions. Here's some naive code that doesn't work

FindInstance[lol==IdentityMatrix[3],PopulateMatrix[lol,3]]

Where

PopulateMatrix[symbol_, dimension_] := 
 Flatten[Table[
   Table[symbol[[i, j]], {j, 1, dimension}], {i, 1, dimension}]]

I feel like this must be close to a correct solution, but it feels ugly. PopulateMatrix[lol,3] returns a desired list of expressions {lol[[1, 1]], lol[[1, 2]], lol[[2, 1]], lol[[2, 2]]} that look like they should play nicely as variables for FindInstance, but it screams at me while doing so, saying that lol[[2,1]] is longer than the depth of the object, because I've not initialised lol as a matrix, but I don't know how to do that.

Any help would be appreciated!

$\endgroup$
5
  • 1
    $\begingroup$ lol = Array[s, {3, 3}]; FindInstance[lol == IdentityMatrix[3], Flatten@lol] $\endgroup$ Dec 16, 2015 at 17:03
  • $\begingroup$ This seems strange to me- why can we call upon s within array without mathematica complaining that s[[3,1]] doesn't exist, but I can't call upon lol[[3,1]] in FindInstance without setting it up? $\endgroup$
    – A Simmons
    Dec 16, 2015 at 18:00
  • $\begingroup$ I'm using s[3,1] ,not s[[3,1]] !! $\endgroup$ Dec 16, 2015 at 18:07
  • 1
    $\begingroup$ Compare Head[s[3, 1]] with Head[s[[3, 1]]] $\endgroup$ Dec 16, 2015 at 18:09
  • $\begingroup$ ah, awesome. thanks, I didn't immediately spot that subtlety $\endgroup$
    – A Simmons
    Dec 16, 2015 at 18:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.