John Cremona on Sat, 14 Jan 2023 15:57:03 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: The companion matrix of a polynomial.


Polynomials have companion matrices.  Matrices do not have them.  The input to matcompanion should be a polynomial, as you can see from ?matcompanion.  

According to GAP's reference (https://docs.gap-system.org/doc/ref/chap24.html) their function CompanionMat also expects a polynomial as input.  So you could ask GAP people why your GAP code does not give an error.  I thought that it might be giving the Companion Matrix of the Characteristic Polynomial of A, but that is not the case.

John

On Sat, 14 Jan 2023 at 03:21, Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
Hi here,

In GAP, the following command can be used to compute a companion
matrix of the polynomial:

gap> A:=[ [ 1, -4, 0 ], [ 1, 0, -2 ], [ 3, 1, 0 ] ];;
gap> CompanionMat(A);
[ [ [ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ], [ -1, 4, 0 ] ], [ [ [
1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ], [ -1, 0, 2 ] ] ]

When I try the similar operation in GP, the corresponding error will
be triggered:

? A=[ 1, -4, 0; 1, 0, -2; 3, 1, 0 ]
%1 =
[1 -4  0]

[1  0 -2]

[3  1  0]

? matcompanion(A)
  ***   at top-level: matcompanion(A)
  ***                 ^---------------
  *** matcompanion: incorrect type in matcompanion (t_MAT).
  ***   Break loop: type 'break' to go back to GP prompt
break>

Any tips for doing this in GP?

Regards,
Zhao
--
Assoc. Prof. Hongsheng Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province