This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'matrix' | |
# Input: an array of the n coefficients [a_n, a_n-1,..., a_1] of | |
# a univariate polynomial p of degree n ([a_n]x^n + [a_n-1]x^n-1 + ... + a_1) | |
# | |
# Output: an array of all n roots of p | |
# | |
# Exploits the fact that the eigenvalues of the companion matrix of the | |
# monic equivalent of p are the roots of p | |
# |