0

I would like to generate 100 random matrices A=[a_{ij}] of size 6 by 6 in (0, 9) using matlab programming satisfying the following properties:

 1. multiplicative inverse:      i.e., a_{ij}=1/a_{ji}      for all i,j=1,2,...,6.
 2. all entries are positive:    i.e., a_{ij}>0             for all i,j=1,2,...,6.
 3. all diagonal elements are 1: i.e., a_{ii}=1             for all i=1,2,..,6.
 4. transitive:                  i.e., a_{ih}*a_{hj}=a_{ij} for all i,j,h=1,2,...,6.

So far, I tried to use a matlab function rand(6)*9. But, I got wrong matrices. I was wondering if anyone could help me?

Here is my matlab code:

clc; clear;
n=6;
m=0;
for i=1:n
    for j=1:n
        for h=1:n
            while m<100  % generate 100 random matrices
                A=rand(n)*9;           % random matrix in (0,9)
                A(i,j)>0;              % positive entries
                A(i,j)==1/A(j,i);      % multiplicative inverse
                A(i,h)*A(h,j)==A(i,j); % transitive
                if i==j && j==h
                    A(i,j)==1;         % diagonal elements are 1
                break;
            end
            m=m+1;
            M{m}=A
        end
    end
end
end
M{:}      
7
  • Why a second question? Commented Jan 5, 2020 at 16:55
  • @Daniel It's a different question. With interval and with out Gaussian noise. Thanks. Commented Jan 5, 2020 at 16:58
  • Actually, all other properties are derived from the transitive property. Commented Jan 5, 2020 at 18:22
  • 1
    A(i,j)>0; does nothing for example Commented Jan 5, 2020 at 18:54
  • 1
    Two slightly different questions, but the answer to both would be the same. Choose 4 values and calculate the remaining ones ( stackoverflow.com/a/59598776/2732801 ) Still not sure how the properties of the random distribution should be preserved. The answer from Burak basically does the same, but produces values larger than 9 for the calculated matrix elements. Commented Jan 5, 2020 at 19:03

2 Answers 2

2
clear; clc
M = cell(1, 100); % preallocate memory
% matrix contains both x & 1/x
% we need a distribution whose multiplication with its inverse is uniform
pd = makedist('Triangular', 'a', 0, 'b', 1, 'c', 1);
for m=1:100 % 100 random matrices
    A = zeros(6); % allocate memory
    % 5 random numbers for 6x6 transitive random matrix
    a = random(pd, 1, 5);
    % choose a or 1/a randomly
    ac = rand(1, 5) < 0.5;
    % put these numbers above the diagonal
    for i=1:5
        if ac(i)
            A(i, i+1) = a(i);
        else
            A(i, i+1) = 1 / a(i);
        end
    end
    % complete the transitivity going above
    for k=flip(1:4)
        for i=1:k
            A(i, i-k+6) = A(i, i-k+5) * A(i-k+5, i-k+6);
        end
    end
    % lower triangle is multiplicative inverse of upper triangle
    for i=2:6
        for j=1:i-1
            A(i,j) = 1 / A(j,i);
        end
    end
    c = random(pd); % triangular random variable between (0,1)
    A = A ./ max(A(:)) * 9 * c; % range becomes (0, 9*c)
    % diagonals are 1
    for i=1:6
        A(i,i) = 1;
    end
    % insert the result
    M{m} = A;
end

There are actually 5 numbers are independent in 6x6 transitive matrix. The others are derived from them as shown in the code.

The reason why triangular distribution is used for these numbers is because pdf of triangular distribution is f(x)=x, and pdf of inverse triangular distribution is f-1(x)=1/x; thus their multiplication becomes uniform distribution. (See pdf of inverse distribution)

A = A ./ max(A(:)) * 9; makes the range (0,9), but there will always be 9 as the maximum element. We need to shrink the result by a random coefficient to obtain the result uniformly distributed in (0,9). Since A is uniformly distributed, we can achieve this again by triangular distribution. (See product distribution)

Another solution to the range issue would be calculating A while its maximum is above 9. This would eliminate the latter problem.

Since all elements of A depends on 5 random variables, the distribution of them will never be perfectly uniform, but the aim here is to maintain a reasonable scale for them.

Sign up to request clarification or add additional context in comments.

9 Comments

@BurakThanks, but it produces values larger than 9 for the calculated matrix elements (some of the results).
@Burak: Unfortunately not really fixed, the numbers are not uniform distributed in the 0...9 range. As stated above, no clue how to achieve this.
Just realized that there is no solution (see my answer). There is no way to fix the code to maintain uniform distributed values. At least you generate values within the expected range and all other requirements are fulfilled. Guess that is the best you can achieve.
@Daniel I do not know what distribution I get, but this is close to uniform I think.
After some research, this is what I find: It say here that pdf of inverse distribution is x^-2*f(x). So if f(x)=x, then f(x)*f^-1(x) becomes uniform. This is the reason why I used triangular distribution, which has pdf f(x)=x..
|
2

It took me a litte to think about your question, but I realized there is no solution.

You require your elements of A to be uniformly distributed in the (0,9) range. You also require a_{ij}*a_{jk}=a_{ik}. Since the product of two uniform distributions is not a unifrom distribution, there is no solution to your question.

1 Comment

If X is triangular distributed and Y is inverse triangular distributed, then what distribution we get from X*Y?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.