フィルターのクリア

Skew symmetric matrix generation

49 ビュー (過去 30 日間)
Mohammed Kagalwala
Mohammed Kagalwala 2019 年 11 月 23 日
編集済み: Mohammed Kagalwala 2019 年 11 月 23 日
Hi,
I'm currently stuck on converting a 3*N x 1, where N is an integer value, vector into chunks of skew symmetric matrices. For example, consider the following vector A = [a;b], where both a and b are 3x1 vectors (here N = 2). I wish to convert this to the following, A_skew = diag(skew(a),skew(b)), a 6x6 matrix. I have a skew_vec() function written that takes a single 3x1 vector as an input and outputs a 3x3 skew-symmetric vector. I know I can use a for loop to solve my problem, however I'm hoping someone else has a better solution (possibly through some smart logical indexing or @(x) ?)
Thank you for the help !
  2 件のコメント
David Hill
David Hill 2019 年 11 月 23 日
an example would be helpful
Mohammed Kagalwala
Mohammed Kagalwala 2019 年 11 月 23 日
Sure so let's say we have A = [1 0 0 2 0 0], I wish to create the following matrix
A_skew = [0 0 0 0 0 0
0 0 -1 0 0 0
0 1 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 -2
0 0 0 0 2 0]
which is simply diag(skew([1 0 0]), skew([2 0 0]))

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

採用された回答

Mohammed Kagalwala
Mohammed Kagalwala 2019 年 11 月 23 日
編集済み: Mohammed Kagalwala 2019 年 11 月 23 日
s = [1 0 0 2 0 0 3 1 2]';
% find size and logical index
N = size(s,1);
tf1 = mod(0:N-1, 3) == 0;
tf2 = mod(0:N-1, 3) == 1;
tf3 = mod(0:N-1, 3) == 2;
ansref = zeros(N,N); % initalize answer
%perform assignment
ansref(tf2,tf3) = diag(-s(tf1));
ansref(tf3,tf2) = diag(s(tf1));
ansref(tf1,tf3) = diag(s(tf2));
ansref(tf3,tf1) = diag(-s(tf2));
ansref(tf1,tf2) = diag(-s(tf3));
ansref(tf2,tf1) = diag(s(tf3));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by