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 u
and v
whose dot product is u.v=0
(i.e., the vectors are perpendicular) are said to be orthogonal.
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
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments