フィルターのクリア

Extract matrices out of a symbolic matrix

2 ビュー (過去 30 日間)
Ahmed Hossam
Ahmed Hossam 2017 年 4 月 20 日
コメント済み: Ahmed Hossam 2017 年 4 月 28 日
Let's assume I have a matrix which looks something like:
Mtx = [2,3*x;4*x^2,1]
Is it "symbolically" possible to get 3 matrices out of this, which look like:
Mtx1 = [2,0;0,1]
Mtx2 = [0,3*x;0,0]
Mtx3 = [0,0;4*x^2,0]
Is there a function, that can do this or should I do it manually?

採用された回答

Andrew Newell
Andrew Newell 2017 年 4 月 20 日
編集済み: Andrew Newell 2017 年 4 月 20 日
It looks like you are trying to extract the diagonal, upper triangular and lower triangular parts of the matrix. These commands will do it for larger matrices as well:
Mtx1 = diag(diag(Mtx));
Mtx2 = triu(Mtx,1);
Mtx3 = tril(Mtx,-1);
  3 件のコメント
Andrew Newell
Andrew Newell 2017 年 4 月 20 日
O.k., for the example you have given, this will do it:
syms x
Mtx = [2,3*x;4*x^2,1];
Mt3 = diff(Mtx,x,2)*x^2/2;
Mt2 = diff(Mtx-Mt3,x,1)*x;
Mt1 = Mtx-Mt2-Mt3;
It would be straightforward to generalize this to higher derivatives, remembering that for the nth derivative you have to divide by n factorial.
Ahmed Hossam
Ahmed Hossam 2017 年 4 月 28 日
you're right!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFinancial Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by