Converts polynomial roots to coefficients.
The PolyCoeff procedure converts polynomial roots to coefficients. The following scheme is used to construct a coefficients from the roots:
The length and complex property of the Coeff object are set automatically. The inverse to this routine is
Example 1
Find coefficients of a polynomial with roots at 1,1 and 2.
uses MtxExpr, Math387, MtxVec, MtxVecEdit, Polynoms;
procedure TForm1.Button1Click(Sender: TObject);
var Roots, Coeff: Vector;
begin
// roots of the polynomial: (x - 1)*(x - 1)*(x - 2)
Roots.SetIt(false,[1, 1, 2]);
PolyCoeff(Roots,Coeff);
// Coeff returns the coefficients of the polynomial [ 1,-4, 5,-2]
// which can be written as: 1*x^3 + -4*x^2 + 5*x - 2
ViewValues(Coeff,'Coefficients');
end;
#include "MtxVecCPP.h" //MtxVecCPP.cpp must be included in the project
#include "Polynoms.hpp"
#include "MtxVecTee.hpp"
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
Vector Roots, Coeff;
// roots of the polynomial: (x - 1)*(x - 1)*(x - 2)
Roots->SetIt(false,OPENARRAY(double,(1, 1, 2)));
PolyCoeff(Roots,Coeff);
// Coeff returns the coefficients of the polynomial [ 1,-4, 5,-2]
// which can be written as: 1*x^3 + -4*x^2 + 5*x - 2
ViewValues(Coeff,"Coefficients");
}
using Dew.Math;
using Dew.Math.Units;
using Dew.Math.Editors;
namespace Dew.Examples
{
private void Example()
{
Vector Roots = new Vector(0);
Vector Coeff = new Vector(0);
// roots of the polynomial: (x - 1)*(x - 1)*(x - 2)
Roots.SetIt(false, new double[] {1,1,2});
Polynoms.PolyCoeff(Roots,Coeff);
// Coeff returns the coefficients of the polynomial [ 1,-4, 5,-2]
// which can be written as: 1*x^3 + -4*x^2 + 5*x - 2
MtxVecEdit.ViewValues(Coeff,"Coefficients");
}
}
Example 2
Find coefficients of a characteristic polynomial uses MtxExpr, Math387, MtxVec, MtxVecEdit, Polynoms;
var Coeff: Vector;
A: Matrix;
begin
A.SetIt(3,3,false,[1, 4, -1,
2, 1, 5,
3, -2, 0]);
PolyCoeff(A,Coeff);
ViewValues(Coeff,'Coefficients');
end;
#include "MtxVecCPP.h" //MtxVecCPP.cpp must be included in the project
#include "Polynoms.hpp"
#include "MtxVecTee.hpp"
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
Vector Coeff;
Matrix A;
A->SetIt(3,3,false,OPENARRAY(double,(1, 4, -1,
2, 1, 5,
3, -2, 0)));
PolyCoeff(A,Coeff);
ViewValues(Coeff,"Coefficients");
}
using Dew.Math;
using Dew.Math.Units;
using Dew.Math.Editors;
namespace Dew.Examples
{
private void Example()
{
Vector Coeff = new Vector(0);
Matrix A = new Matrix(0,0);
A.SetIt(3,3,false, new double[] {1, 4, -1,
2, 1, 5,
3, -2, 0});
Polynoms.PolyCoeff(A,Coeff);
MtxVecEdit.ViewValues(Coeff,"Coefficients");
}
}