0
votes

I have a matrix A which is

A=[1 0 0 1 0; 
   0 1 1 0 0; 
   0 0 1 1 0; 
   1 1 1 0 0]

And a given vector v=[ 0 0 1 1 0] which has two elements one. I have to change the position of element one such that the new vector v is orthogonal to all the rows in the matrix A. How can I do it in Matlab?

To verify the correct answer, just check gfrank([A;v_new]) is 5 (i.e v_new=[0 1 0 0 1]).

Note that: Two vectors uand v whose dot product is u.v=0 (i.e., the vectors are perpendicular) are said to be orthogonal.

2
v_new is not orthogonal to the rows of A. Do you mean v_new=[0 0 0 0 1]?AVK

2 Answers

1
votes

As AVK also mentioned in the comments, v_new = [0 1 0 0 1] is not orthogonal to all rows of A.

Explanation:-

A=[1 0 0 1 0; 
   0 1 1 0 0; 
   0 0 1 1 0; 
   1 1 1 0 0]

For A(1,:).*v = 0 to A(4,:).*v = 0,

0 x x 0 x        % elements of v so that it's orthagonal to the 1st row of A
x 0 0 x x        % -------------------------------------------- 2nd row of A
x x 0 0 x        % -------------------------------------------- 3rd row of A
0 0 0 x x        % -------------------------------------------- 4th row of A

where 0 represents the terms which have to be 0 and x represents the terms which can be either 0 or 1.

If you look as a whole, first 4 columns of v have to be zero so that the output is orthagonal to all rows of A. The 5th column can either be zero or 1.

So, v_new can either be: v_new = [0 0 0 0 1] or v_new = [0 0 0 0 0]

From above explanation, you can also see that [0 1 0 0 1] is not orthagonal to 2nd and 4th row of A


Solution:-

To find v_new, you can use null function as: v_new = null(A).'
which gives: v_new = [0 0 0 0 1] for which gfrank([A;v_new]) also gives 5.

0
votes

Maybe this will help you see the orthogonality between two vectors in N dimension.

N=100;
B1 = ones(1,N);
B2 = -1*ones(1,N/2); 
B2 = [ones(1,N/2) B2];
B2 = transpose(B2);
B3 = dot(B1,B2);

The above code generates two vectors in N dimension. To check for orthogonality just transpose one of the vectors and multiply with the other one. You should get zero if they are Orthogonal.

The example I used makes sure that I get zero indeed.