How to subs in a polynomial a matrix

7 vues (au cours des 30 derniers jours)
Fernando Pérez Lara
Fernando Pérez Lara le 9 Déc 2018
Modifié(e) : madhan ravi le 13 Déc 2018
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 commentaires
Bruno Luong
Bruno Luong le 9 Déc 2018
Modifié(e) : Bruno Luong le 9 Déc 2018
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 le 9 Déc 2018
Modifié(e) : madhan ravi le 9 Déc 2018
Thanks Bruno didn't realise at the first sight.

Connectez-vous pour commenter.

Réponses (1)

Astha Singh
Astha Singh le 13 Déc 2018
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 commentaire
madhan ravi
madhan ravi le 13 Déc 2018
Modifié(e) : madhan ravi le 13 Déc 2018
+1 , Thank you Astha Singh , read about this function a long time back but could recall at the time.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Polynomials dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by