How to generate random projection matrices?
Show older comments
As it is said in the question, I am looking for a Matlab function that generates random projection matrices, so that I can use it for linear programming.
Answers (3)
KALYAN ACHARJYA
on 24 Jul 2019
Edited: KALYAN ACHARJYA
on 24 Jul 2019
function P=projection_mat(n)
A=colbasis(magic(n));
P=A*inv(A'*A)*A';
end
The colbasis function is here
Here n represent size of square matrix. Please note that I have answered this question from here
Command Window:
>> y=projection_mat(6)
y =
0.7500 -0.0000 0.2500 0.2500 -0.0000 -0.2500
-0.0000 1.0000 0.0000 -0.0000 -0.0000 0.0000
0.2500 0.0000 0.7500 -0.2500 -0.0000 0.2500
0.2500 -0.0000 -0.2500 0.7500 -0.0000 0.2500
-0.0000 -0.0000 -0.0000 -0.0000 1.0000 -0.0000
-0.2500 0.0000 0.2500 0.2500 -0.0000 0.7500
You can generate any size matries, just pass the same size matrix to colbasis function.
Hope it helps!
4 Comments
Rufat Imanov
on 25 Jul 2019
Rufat Imanov
on 25 Jul 2019
KALYAN ACHARJYA
on 25 Jul 2019
Edited: KALYAN ACHARJYA
on 25 Jul 2019
Is there any necessity having fixed size matrices?
>> y=projection_mat(6)
y =
0.7500 -0.0000 0.2500 0.2500 -0.0000 -0.2500
-0.0000 1.0000 0.0000 -0.0000 -0.0000 0.0000
0.2500 0.0000 0.7500 -0.2500 -0.0000 0.2500
0.2500 -0.0000 -0.2500 0.7500 -0.0000 0.2500
-0.0000 -0.0000 -0.0000 -0.0000 1.0000 -0.0000
-0.2500 0.0000 0.2500 0.2500 -0.0000 0.7500
>> y=projection_mat(5)
y =
1.0000 -0.0000 -0.0000 -0.0000 -0.0000
-0.0000 1.0000 -0.0000 -0.0000 -0.0000
-0.0000 -0.0000 1.0000 -0.0000 0.0000
-0.0000 -0.0000 -0.0000 1.0000 0.0000
-0.0000 -0.0000 -0.0000 -0.0000 1.0000
>>
Rufat Imanov
on 25 Jul 2019
Bruno Luong
on 25 Jul 2019
Edited: Bruno Luong
on 25 Jul 2019
n = 5
r = 3; % rank, dimension of the projection subspace
[Q,~] = qr(randn(n));
Q = Q(:,1:r);
P = Q*Q' % random projection matrix P^2 = P, rank P = r
5 Comments
Rufat Imanov
on 25 Jul 2019
Edited: Rufat Imanov
on 25 Jul 2019
Bruno Luong
on 25 Jul 2019
Edited: Bruno Luong
on 25 Jul 2019
Yes I'm sure of P^2 = P and rank(P) is as specified. That's pretty much a projection by definition.
Actually P^n = P for any n >= 1 (you project an object n time, ot does not change after the first time).
I don't know why your expect columns (or rows, since P is symmetric) are orthogonal. The projection of basic vectors is in general NOT orthogonal (e.g., the 3D cube drawed on your computer screen does not have right angles in general).
n = 5
r = 3; % rank, dimension of the projection subspace
[Q,~] = qr(randn(n));
Q = Q(:,1:r);
P = Q*Q' % random projection matrix P^2 = P, rank P = r
Outputs:
n =
5
P =
0.3071 -0.1744 -0.3665 -0.0818 -0.2034
-0.1744 0.9371 -0.1236 -0.1015 0.0542
-0.3665 -0.1236 0.7542 -0.1770 0.0667
-0.0818 -0.1015 -0.1770 0.6461 0.4247
-0.2034 0.0542 0.0667 0.4247 0.3555
>> P^2
ans =
0.3071 -0.1744 -0.3665 -0.0818 -0.2034
-0.1744 0.9371 -0.1236 -0.1015 0.0542
-0.3665 -0.1236 0.7542 -0.1770 0.0667
-0.0818 -0.1015 -0.1770 0.6461 0.4247
-0.2034 0.0542 0.0667 0.4247 0.3555
>> P
P =
0.3071 -0.1744 -0.3665 -0.0818 -0.2034
-0.1744 0.9371 -0.1236 -0.1015 0.0542
-0.3665 -0.1236 0.7542 -0.1770 0.0667
-0.0818 -0.1015 -0.1770 0.6461 0.4247
-0.2034 0.0542 0.0667 0.4247 0.3555
>> norm(P^2-P)
ans =
5.8312e-16
>> rank(P)
ans =
3
Rufat Imanov
on 25 Jul 2019
Bruno Luong
on 25 Jul 2019
Edited: Bruno Luong
on 25 Jul 2019
Sorry I think the only projection matrix that is orthogonal is diagonal matrix with 1 or 0 on the diagonal. So there is no really randomness for what you ask.
Bruno Luong
on 26 Jul 2019
Edited: Bruno Luong
on 26 Jul 2019
I wonder if you mistaken "orthogonal projection matrix" and "projection matrix that is orthogonal". They are not the same.
Mine is "orthogonal projection matrix", which is projection matrix (P^2==P) that has additional properties
- symmetric
- all eigen values are 0 or 1.
Image Analyst
on 25 Jul 2019
0 votes
Not sure what you mean by projection, but the radon transform does projections. That's its claim to fame. It basically projects a matrix along any angle and gives you the sum of the interpolated values along the projection angle. This is the crucial function for reconstructing 3-D volumetric CT images from 2-D projections.
The radon() function requires the Image Processing Toolbox.
Categories
Find more on Lengths and Angles in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!