フィルターのクリア

Function to solve unknowns in Ka=b. Where K is a square matrix fully known, however, knowns and unknowns are scattered in a & b.

2 ビュー (過去 30 日間)
JT
JT 2020 年 11 月 16 日
コメント済み: JT 2020 年 11 月 16 日
Hello,
I am trying to write a function to solve unknowns in Ka=b. The tricky part is unknowns are scattered in a & b and it has to work for different compatible matrix sizes. The inputs are K, a, b and I am trying to output the solved variables in a & b. Are there functions already similar to this? How would you go about this process wise?
Assume:
  1. K is a square matrix fully known
  2. a & b are column matrices with knowns and unknowns
  3. dimensions can vary but assume they are always compatible.
  4 件のコメント
Bruno Luong
Bruno Luong 2020 年 11 月 16 日
編集済み: Bruno Luong 2020 年 11 月 16 日
This is a careless example given: rank Ksys is 1, so not invertible.
JT
JT 2020 年 11 月 16 日
Apologies. Assume Ksys is an invertible matrix.

サインインしてコメントする。

回答 (1 件)

Bruno Luong
Bruno Luong 2020 年 11 月 16 日
編集済み: Bruno Luong 2020 年 11 月 16 日
You might need to carry out some normalization of a, b so that they are unitless before doing this.
% Generate test data
m = 12;
n = 10;
K = rand(m,n);
a = rand(n,1);
b = K*a;
known_a=rand(size(a))>0.4;
known_b=rand(size(b))>0.4;
% Solve a(~known_a) and b(~known_b)
% from K, a(known_a) and b(known_b)
tlsqflag = true; % recommend true
[m,n] = size(K);
M = [K, -eye(m)];
known_ab = [known_a(:); known_b(:)];
X = zeros(m+n,1);
X(known_ab,1) = [a(known_a); b(known_b)];
if ~tlsqflag
% not recommended
Y = -M*X;
X(~known_ab) = M(:,~known_ab)\Y;
else
% recommended method
[~,~,V] = svd([M(:,~known_ab), M*X],0);
Vend = V(:,end);
X(~known_ab) = Vend(1:end-1)/Vend(end);
end
a = X(1:n)
b = X(n+1:end)
% Check residu
norm(K*a-b)/norm(b)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by