Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.7K Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Replace 0 in a diagonal matrix with 1 one at a time or 3 at a time

Posted 10 years ago

Suppose you have the following

DiagonalMatrix[{0, 0, 0, 0, 0}]

={{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}

I want to replace one 0 with one 1 in order nxn as n goes from 1 to 5 in this case.so that you would get 5 separate arrays.

={{1, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}

then

={{0, 0, 0, 0, 0}, {0,1, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}

then

={{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}

And so on. The following should work, but obviously doesn't...

Table[DiagonalMatrix[{0, 0, 0, 0, 0}][[i, i]] /. {0 -> 1}, {i, 1, 5}]

I also need to choose, in a larger array, 3 0s at a time and replace with 1s. But all such array combination must be created.

For above example,

{{1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}

can be the first combination. Then

{{0, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 0, 1, 0}, {0, 0, 0, 0, 0}}

and so on.

being the second. But there are far more combination possible.. I need to find all possibles.

Any help is greatly appreciated.

POSTED BY: bored dude
2 Replies
Posted 10 years ago

Thank you the reply. But that permutation done on the actual list of 42 elements choosing 3 elements at a time only did generate the lists, but upon trying to turn it into an array using the diagonal matrix crashed the computer.

I might have to change my approach. My initial approach was to dot product the arrays with 1 and 0s with a list of same length containing values. That values has to be maximized using the maximize function.

I might have to re think the entire process.

DO you have any tips on how to approach this problem? I posted the initial problem here

POSTED BY: bored dude

Hi bored dude,

here one short possible answer to question #1:

dd = DiagonalMatrix /@ DiagonalMatrix[ConstantArray[1, 5]];
MatrixForm /@ dd

giving:

enter image description here

to question #2:

ddd = DiagonalMatrix /@ Permutations[{0, 0, 1, 1, 1}];
MatrixForm /@ ddd

giving:

enter image description here

Regards -- Henrik

POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard