如何在matlab中判断b∈Col A还是b∉Col A? A 是 m x n 矩阵,其中 m >= n,b 是向量。是否已经有一个内置函数可以实现此目的,或者我需要创建一个函数吗?如果 b ∈ Col A,我将如何确定矩阵 A 是否具有正交列/是否正交?
最佳答案
您可以使用 ismember
,如之前的答案中所述。
// some sample data
A = [eye(3); zeros(3)];
v = [0; 1; 0; 0; 1; 0];
ismember(A', v', 'rows')
要检查正交性,您可以执行以下操作
// A scalar initialised outside the for-loop. It stores sums of inner products.
dp = 0;
// Take the columns of A one by one and compute the inner product with all subsequent columns. If A is orthogonal, all the inner products have to be zero and, hence, their sum has to be zero.
for i = 1:size(A, 2)
dp = dp + sum(A(:, i)'*A(:, i+1:end));
end
if (dp == 0)
disp('The columns are orthogonal')
else
disp('The columns are not orthogonal')
end
要拥有正交列,每列的范数必须为 1,因此:
// Check each column for unit length
M = mat2cell(A, size(A, 1), ones(size(A, 2), 1));
if find(cellfun(@(x)norm(x,2), M) ~= 1)
disp('Columns are not of unit length')
else
disp('Columns are of unit length')
end
请注意,如果 m=n(因为您允许这种情况),所有这些操作都会变得更简单、更快。
关于matlab - 如何检查向量b是否在A列中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23148476/