필터 지우기
필터 지우기

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 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