0

I have to get the unknown matrix by changing the form of a known matrix considering the following rules:

H = [-P'|I] %'
G = [I|P]

where

  • H is a known matrix
  • G is an unknown matrix which has to be calculated
  • I is the identity matrix

So for example, if we had a matrix,

H = [1 1 1 1 0 0; 
     0 0 1 1 0 1; 
     1 0 0 1 1 0]

its form has to be changed to

H = [1 1 1 1 0 0; 
     0 1 1 0 1 0; 
     1 1 0 0 0 1]

So

-P' = [1 1 1; 
       0 1 0; 
       1 1 0] 

and in case of binary matrices -P = P.

Therefore

 G = [1 0 0 1 1 1; 
      0 1 0 0 1 0; 
      0 0 1 1 1 0]

I know how to solve it on paper by performing basic row operations but haven't figured out how to solve it using MATLAB yet.

What is the method for solving the given problem?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Niko Gamulin
  • 66,025
  • 95
  • 221
  • 286
  • Your comment about -P == P is only true if you are restricting this to an integer field. You should make that explicit in your question. –  Apr 27 '10 at 09:33
  • And it would help greatly if you formatted your Matlab statements as if they were code. – High Performance Mark Apr 27 '10 at 11:00
  • @Niko: Please have a look at the help to see how post can be formatted to make them more readable. – Jonas Apr 27 '10 at 11:23
  • Two issues: 1) Shouldn't `-P'` be equal to `[1 1 1; 0 1 1; 1 1 0]` in your example, which would give `G = [1 0 0 1 0 1; 0 1 0 1 1 1; 0 0 1 1 1 0]`? 2) You don't specify how to reorder `H`. Do columns need to be swapped, or can columns not in `I` simply be shifted to the left? In other words, is `[1 1 1; 0 1 1; 1 0 1]` a valid value for `-P'`? – gnovice Apr 27 '10 at 13:48
  • You need to perform basic row operations with Matlab too. I suggest you start with the Wikipedia article on [Permutation Matrices][1]. Update your question when you've made a start. [1]: http://en.wikipedia.org/wiki/Permutation_matrix – High Performance Mark Feb 04 '11 at 03:15

1 Answers1

1

If the order of columns in -P' doesn't matter, here's one solution using the function ISMEMBER:

>> H = [1 1 1 1 0 0; 0 0 1 1 0 1; 1 0 0 1 1 0];  %# From above
>> pColumns = ~ismember(H',eye(3),'rows')  %'# Find indices of columns that
                                            %#   are not equal to rows
pColumns =                                  %#   of the identity matrix

     1
     0
     1
     1
     0
     0

>> P = -H(:,pColumns)'  %'# Find P

P =

    -1     0    -1
    -1    -1     0
    -1    -1    -1

>> G = logical([eye(3) P])  %# Create the binary matrix G

G =

     1     0     0     1     0     1
     0     1     0     1     1     0
     0     0     1     1     1     1

NOTE: This solution will work properly for integer or binary values in H. If H has floating-point values, you will likely run into an issue with floating-point comparisons when using ISMEMBER (see here and here for more discussion of this issue).

Community
  • 1
  • 1
gnovice
  • 125,304
  • 15
  • 256
  • 359