Dew MtxVec NET
PolyEval Routines
Summary
Evaluate a polynomial.

Unit
Polynoms

Declaration
Function PolyEval(Val: TCplx; Coeff: TVec): TCplx;

Description
Evaluates a polynomial with coefficients Coeff at complex value Val and returns complex results.
 See Also 
PolyFit 
TPiecePoly 

Example 1

uses MtxExpr, Math387, MtxVec, MtxVecEdit, MtxVecTee,Polynoms; procedure TForm1.Button1Click(Sender: TObject); var X, Y, Coeff: Vector; begin X := Ramp(10,-5,1); // X = [-5,-4,-3,-2,-1, 0, 1, 2, 3, 4] // construct a parabola Coeff.SetIt(false,[2, -1, 3]); PolyEval(X,Coeff,Y); // Y now holds the values of polynomial, evaluated at all X.Values DrawIt(X,Y,'Parabola'); end;
#include "MtxVecCPP.h" //MtxVecCPP.cpp must be included in the project #include "Polynoms.hpp" #include "MtxVecTee.hpp" #include "MtxVecEdit.hpp" void __fastcall TForm1::BitBtn1Click(TObject *Sender) { Vector X,Y,Coeff; X->Size(10); X->Ramp(-5,1); // X = [-5,-4,-3,-2,-1, 0, 1, 2, 3, 4] // construct a parabola Coeff->SetIt(false,OPENARRAY(double,(2, -1, 3))); PolyEval(X,Coeff,Y); // Y now holds the values of polynomial, evaluated at all X.Values DrawIt(X,Y,"Parabola",false); }
using Dew.Math; using Dew.Math.Units; using Dew.Math.Tee; namespace Dew.Examples { private void Example() { Vector X = new Vector(0); Vector Y = new Vector(0); Vector Coeff = new Vector(0); X.Size(10); X.Ramp(-5,1); // X = [-5,-4,-3,-2,-1, 0, 1, 2, 3, 4] // construct a parabola Coeff.SetIt(false,new double[] {2, -1, 3}); Polynoms.PolyEval(X,Coeff,Y); // Y now holds the values of polynomial, evaluated at all X.Values TeeChart.DrawIt(X,Y,"Parabola",false); } }


Declaration
Function PolyEval(Val: TSample; Coeff: TVec): TSample;

Description
Evaluates a polynomial with coefficients Coeff at real value Val and returns real result.
Declaration
Procedure PolyEval(Val, Coeff, Result: TVec);

Description
Evaluates a polynomial with coefficients Coeff at value Val and returns the results in Result.
Declaration
Procedure PolyEval(Val, Coeff: TVec; R: TMtx; DegFreedom: Integer; L2R: TSample; Results, Delta: TVec);

Description
Evaluate a polynomial with coefficients Coeff at value Val. The order of polynomial (N) is determined as: N := Coeff.Length - 1. The algorithm employed uses Horners rule. The following formula is used to evaluate the polynomial:
P(x) = coeff[0]*x^n + coeff[1]*x^(n-1) + .. + coeff[n]
To estimate the error of polynomial interpolation after a call to PolyFit additional parameters have to be passed to the routine. The R matrix represents the Cholesky factor of the Vandermonde matrix, the DegFreedom represents the residuals degree of freedom and L2R represents the L2 norm of the residuals. PolyFit method calculates the Coeff, R, DegFreedom and L2R parameters. The results of polynomial evaluation are returned in Results vector. The Delta vector returns the error estimates for Results.

Copyright 2008 Dew Research
http://www.dewresearch.com