フィルターのクリア

How to subs in a polynomial a matrix

6 ビュー (過去 30 日間)
Fernando Pérez Lara
Fernando Pérez Lara 2018 年 12 月 9 日
編集済み: madhan ravi 2018 年 12 月 13 日
Hello,
I'm trying to subs in the EQ polynomial a matrix A. The problem is when I subs this polynomial using subs(EQ, x, A)
syms x;
A = [1 2 3;
4 5 6;
7 8 9]
EQ = x^3 + 2*x^2 - 5*x + 3
subs(EQ, x, A)
OUTPUT: 1, 9, 33
79, 153, 261
409, 603, 849
WHAT I WANT: 526 641 756
1177 1445 1713
1828 2249 2670
  3 件のコメント
Bruno Luong
Bruno Luong 2018 年 12 月 9 日
編集済み: Bruno Luong 2018 年 12 月 9 日
Logic? Seems pretty straigh-forward to me. Expression using power on matrix is repeated matrix multiplication (not element wise multiplication):
>> A^3
ans =
468 576 684
1062 1305 1548
1656 2034 2412
>> A*A*A
ans =
468 576 684
1062 1305 1548
1656 2034 2412
>>
>> A^3 + 2*A^2 - 5*A + 3
ans =
526 641 756
1177 1445 1713
1828 2249 2670
madhan ravi
madhan ravi 2018 年 12 月 9 日
編集済み: madhan ravi 2018 年 12 月 9 日
Thanks Bruno didn't realise at the first sight.

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

回答 (1 件)

Astha Singh
Astha Singh 2018 年 12 月 13 日
Substitution of a matrix into a polynomial using 'subs()' command, is done in element-by-element manner, which leads to the observed result.
In order to substitute a matrix in a polynomial and use the standard matrix operation rules, you would need to use 'polyvalm()' command.
I am attaching a sample code to achieve the same:
syms x;
A = [1 2 3;4 5 6;7 8 9];
EQ = x^3 + 2*x^2 - 5*x + 3;
% Get a row vector containing the numeric coefficients of the polynomial 'EQ'
b=sym2poly(EQ);
% Substitute the square matrix 'A' into the polynomial 'EQ'
polyvalm(b,A)
Please note that here the command 'polyvalm(b,A)' is equivalent to 'A^3 + 2*A^2 - 5*A + 3*eye(3)'. The constant times the identity matrix 'eye(3)' replaces the constant term of 'EQ'.
If on the other hand, the constant is simply added, as in: 'A^3 + 2*A^2 - 5*A + 3', it leads to the number 3 being added to all the elements of the matrix.
  1 件のコメント
madhan ravi
madhan ravi 2018 年 12 月 13 日
編集済み: madhan ravi 2018 年 12 月 13 日
+1 , Thank you Astha Singh , read about this function a long time back but could recall at the time.

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

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by