How to subs in a polynomial a matrix

6 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Number Theory 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by