Orthonormal basis for range of symbolic matrix
orth(
computes an orthonormal basis for the range of
A
)A
.
orth(
computes
an orthonormal basis using a real scalar product in the orthogonalization process.A
,'real'
)
orth(
computes a non-normalized orthogonal basis. In this case, the vectors forming the columns of
A
,'skipnormalization'
)B
do not necessarily have length 1.
Compute an orthonormal basis of the range of this matrix. Because these numbers are not symbolic objects, you get floating-point results.
A = [2 -3 -1; 1 1 -1; 0 1 -1]; B = orth(A)
B = -0.9859 -0.1195 0.1168 0.0290 -0.8108 -0.5846 0.1646 -0.5729 0.8029
Now, convert this matrix to a symbolic object, and compute an orthonormal basis:
A = sym([2 -3 -1; 1 1 -1; 0 1 -1]); B = orth(A)
B = [ (2*5^(1/2))/5, -6^(1/2)/6, -(2^(1/2)*15^(1/2))/30] [ 5^(1/2)/5, 6^(1/2)/3, (2^(1/2)*15^(1/2))/15] [ 0, 6^(1/2)/6, -(2^(1/2)*15^(1/2))/6]
You can use double
to convert this result to the
double-precision numeric form. The resulting matrix differs from the matrix returned by the
MATLAB®
orth
function because these functions use different versions of the
Gram-Schmidt orthogonalization algorithm:
double(B)
ans = 0.8944 -0.4082 -0.1826 0.4472 0.8165 0.3651 0 0.4082 -0.9129
Verify that B'*B = I
, where I
is the identity
matrix:
B'*B
ans = [ 1, 0, 0] [ 0, 1, 0] [ 0, 0, 1]
Now, verify that the 2-norm of each column of B
is 1:
norm(B(:, 1)) norm(B(:, 2)) norm(B(:, 3))
ans = 1 ans = 1 ans = 1
Compute an orthonormal basis of this matrix using
'real'
to avoid complex conjugates:
syms a A = [a 1; 1 a]; B = orth(A,'real')
B = [ a/(a^2 + 1)^(1/2), -(a^2 - 1)/((a^2 + 1)*((a^2 -... 1)^2/(a^2 + 1)^2 + (a^2*(a^2 - 1)^2)/(a^2 + 1)^2)^(1/2))] [ 1/(a^2 + 1)^(1/2), (a*(a^2 - 1))/((a^2 + 1)*((a^2 -... 1)^2/(a^2 + 1)^2 + (a^2*(a^2 - 1)^2)/(a^2 + 1)^2)^(1/2))]
Compute an orthogonal basis of this matrix using
'skipnormalization'
. The lengths of the resulting vectors (the
columns of matrix B
) are not required to be 1
syms a A = [a 1; 1 a]; B = orth(A,'skipnormalization')
B = [ a, -(a^2 - 1)/(a*conj(a) + 1)] [ 1, -(conj(a) - a^2*conj(a))/(a*conj(a) + 1)]
Compute an orthogonal basis of this matrix using
'skipnormalization'
and 'real'
:
syms a A = [a 1; 1 a]; B = orth(A,'skipnormalization','real')
B = [ a, -(a^2 - 1)/(a^2 + 1)] [ 1, (a*(a^2 - 1))/(a^2 + 1)]
Calling orth
for numeric arguments
that are not symbolic objects invokes the MATLAB orth
function. Results returned by MATLAB orth
can
differ from results returned by orth
because these
two functions use different algorithms to compute an orthonormal basis.
The Symbolic Math Toolbox™ orth
function uses
the classic Gram-Schmidt orthogonalization algorithm. The MATLAB orth
function
uses the modified Gram-Schmidt algorithm because the classic algorithm
is numerically unstable.
Using 'skipnormalization'
to
compute an orthogonal basis instead of an orthonormal basis can speed
up your computations.
orth
uses the classic Gram-Schmidt orthogonalization
algorithm.