What are the commands for...

136 views (last 30 days)
Hello there!
I am looking for the commads for...
the basis of a row space.
the basis of a column space.
and the basis of a null space.
Are there such commands out there?
Kind regards.
Morne' Breitenbach

Accepted Answer

John D'Errico
John D'Errico on 4 Jun 2020
Edited: John D'Errico on 4 Jun 2020
Column space basis orthogonal representations are obtained in MATLAB using either null or orth. In fact, they work regardless of whether the matrices are symbolic or floating point.
A = magic(4)
A =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
rank(A)
ans =
3
Since A has rank 3, the null space will have dimensioon 1.
null(A)
ans =
-0.223606797749979
-0.670820393249937
0.670820393249937
0.223606797749979
orth(A)
ans =
-0.5 0.670820393249937 0.5
-0.5 -0.223606797749979 -0.5
-0.5 0.223606797749979 -0.5
-0.5 -0.670820393249937 0.5
orth(A) spans the column space, which must have dimension 3. Note that on floating point inputs, null and otrth return results normalized to have unit euclidean norm for each vector.
Both column spaces will be in an ortho-normal form, thus they have Euclidean norms of 1, and the vectors will be orthogonal. At least so to within floating point precision.
B = orth(A);
B'*B
ans =
1 -1.47568580327613e-16 -5.55111512312578e-17
-1.47568580327613e-16 1 1.11022302462516e-16
-5.55111512312578e-17 1.11022302462516e-16 1
All of this works on symbolic matrices too, though the vectors need not be as neatly normalized.
B = colspace(sym(A))
B =
[ 1, 0, 0]
[ 0, 1, 0]
[ 0, 0, 1]
[ 1, 3, -3]
B'*B
ans =
[ 2, 3, -3]
[ 3, 10, -9]
[ -3, -9, 10]
So colspace here returned a basis that is independent, but not orthogonal.
On fully symbolic arrays, thus those with some or all non-numeric elements, there are other things we need to watch out for.
syms x
>> A = [1 2 3;4 5 6;7 8 x]
A =
[ 1, 2, 3]
[ 4, 5, 6]
[ 7, 8, x]
>> null(A)
ans =
Empty sym: 3-by-0
>> orth(A)
ans =
[ 66^(1/2)/66, (3*11^(1/2))/11, (x/6 - 3/2)/(abs(x/3 - 3)^2 + 2*abs(x/6 - 3/2)^2)^(1/2)]
[ (2*66^(1/2))/33, 11^(1/2)/11, -(x/3 - 3)/(abs(x/3 - 3)^2 + 2*abs(x/6 - 3/2)^2)^(1/2)]
[ (7*66^(1/2))/66, -11^(1/2)/11, (x/6 - 3/2)/(abs(x/3 - 3)^2 + 2*abs(x/6 - 3/2)^2)^(1/2)]
>> colspace(A)
ans =
[ 1, 0, 0]
[ 0, 1, 0]
[ 0, 0, 1]
Both orth and colspace have returned representations for basis vectors of the column space of A. Even though we know that when x has one spacific value, those spaces will have the wrong dimensions.
det(A)
ans =
27 - 3*x
solve(det(A) == 0)
ans =
9
Because when x==9, the matrix is now rank deficient, and therefore the various bases will have different dimensions. So be careful when applying all of these tools to general symbolic arrays.
Finally, see that when applied to symbolic arrays, the vectors will not always have unit norm. The symbolic toolbox seems to be a bit arbitrary here in the choice of vector normalizations.
A = sym(randi(5,3,4))
A =
[ 1, 1, 5, 1]
[ 2, 5, 1, 5]
[ 5, 3, 3, 1]
>> B = null(A)
B =
4/7
-17/14
-1/14
1
>> norm(B)
ans =
(98^(1/2)*275^(1/2))/98
So the null space vector did not have unit norm.
B = orth(A)
B =
[ 30^(1/2)/30, (2*15^(1/2)*187^(1/2))/2805, (19*2^(1/2)*187^(1/2))/374]
[ 30^(1/2)/15, (49*15^(1/2)*187^(1/2))/2805, -(2^(1/2)*187^(1/2))/187]
[ 30^(1/2)/6, -(4*15^(1/2)*187^(1/2))/561, -(3*2^(1/2)*187^(1/2))/374]
>> B'*B
ans =
[ 1, 0, 0]
[ 0, 1, 0]
[ 0, 0, 1]
Orth did yield results that were orthogonal, though it did not find as simple a result as colspace does next. Colspace may have decided that the matrix has rank 3, and therefore a good basis for the column space is just the 3x3 identity matrix.
B = colspace(A)
B =
[ 1, 0, 0]
[ 0, 1, 0]
[ 0, 0, 1]
I assume that colspace will be significantly faster than orth or null, when applied to symbolic arrays.
So probably more than you wanted to know about the various basis forming tools in MATLAB.
  3 Comments
Morne' Breitenbach
Morne' Breitenbach on 4 Jun 2020
How would you use greater then and less than?
Morne' Breitenbach
Morne' Breitenbach on 4 Jun 2020
Never mind I found out how to do it.

Sign in to comment.

More Answers (1)

madhan ravi
madhan ravi on 4 Jun 2020
https://www.mathworks.com/help/symbolic/colspace.html - see bottom of the page for similar functionality functions.
  4 Comments
Morne' Breitenbach
Morne' Breitenbach on 4 Jun 2020
Awesome thanks. Enjoy your day or night wherever you are in this world.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!