VanBaffo
VanBaffo

Reputation: 259

How to create an orthogonal matrix in Matlab with one fixed column

I want to create a square NxN matrix orthogonal, with the constraint that the first column is a column vector of k*ones(N,1), where k is a constant at choice. Is there any procedure?

I.e.

A= [k * *;k * *;k * *]

is a 3x3 matrix, where the first column is a vector k*ones(3,1), and the other two vectors have to be created in such a way the matrix is orthogonal

Upvotes: 0

Views: 1759

Answers (3)

Florian
Florian

Reputation: 1824

Alternatively:

kk = k*ones(3,1); % fixed first column (could be anything)
X = [kk, null(kk')']

gives you a square matrix with mutually orthogonal columns, no matter what's the vector kk. It will be an orthonormal matrix only when norm(k)==1 (which implies k=1/sqrt(3) in your examples, as the others have noted). Note that the first case does not imply its rows are orthogonal, whereas the second one does.

Upvotes: 2

Mefitico
Mefitico

Reputation: 1116

Maybe this should be posted on Math.StackEchange where equations can be typed properly if you want a proper theoretical explanation. But if just want the code...

First, if N is the dimension of your matrix, this constrains the value of k to:

k=sqrt(1/N);
A(1,:) = k*ones(1,N);

Then, the second row can be constructed with:

A(2,:) = sqrt(0.5)*[1,-1,zeros(1,N-2)];

This creates a simple vector orthogonal to the first.

The third line can be computed with:

aux = [1,1,-2,zeros(1,N-3)];
A(3,:) = aux/norm(aux);

The fourth:

aux = [1,1,1,-3,zeros(1,N-4)];
A(4,:) = aux/norm(aux);

And so on.

In short:

A=zeros(N);
k=sqrt(1/N);
A(1,:) = k*ones(1,N);
for i=2:N
    aux = [ones(1,i-1),-(i-1),zeros(1,N-i)];
    A(i,:) = aux/norm(aux);
end

Upvotes: 2

dmuir
dmuir

Reputation: 4431

I'm sorry I can't quote MATLAB code, but I'm sure this will be straightforward to code.

What you want is a Householder reflector These are othonormal matrices that are symmetric (and so are their own inverses). Given a vector v you can find a reflector H so that

H*v = a*e1

where a is += length of v and e1 is (1,0,..)'

I'd imagine MATLAB has a routine for this.

Given the properties of H this means that the first column of H is parallel to v, and the other columns are orthogonal to v and to each other.

So if you scale the first column of H (it is of length 1) appropriately, you have your desired matrix.

Upvotes: 1

Related Questions