[TOC]

compan

Companion matrix

Introduction

A companion matrix has the following form

Roots of the polynomial ​​ are eigenvalues of , where

This can be seen by expressing as the determinant:

Roots of ​ are eigenvalues of , which are also roots of .

Usage

compan(p)

Example

Input
p = [1 2 3];
c = compan(p)
eig(c)
roots(p)
Output
c = 
-2.0000  -3.0000
 1.0000   0.0000

ans = 
-1.0000 + 1.4142i
-1.0000 - 1.4142i

ans = 
-1.0000 - 1.4142i
-1.0000 + 1.4142i