tags:

views:

58

answers:

2

Hi,

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

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

where

  • H is known matrix
  • G is unknown matrix which has to be calculated
  • I is 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.

I would be very thankful if anyone of you could suggest any method for solving the given problem.

A: 

You need to perform basic row operations with Matlab too. I suggest you start with the Wikipedia article on Permutation Matrices. Update your question when you've made a start.

High Performance Mark
+1  A: 

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).

gnovice

related questions