• https://me.yahoo.com
COST (GBP)
0.50
0.00
0

# Poly Eval

viewed 5500 times and licensed 460 times
Evaluates a polynomial of degree N.
Controller: CodeCogs

C++

## Overview

Evaluates polynomial of degree N:
$y&space;=&space;C_0&space;+&space;C_1&space;x&space;+&space;C_2&space;x^2&space;+&space;...&space;+&space;C_N&space;x^N$

Coefficients are stored in reverse order, i.e.
$coef[0]&space;=&space;C_N&space;&space;,&space;...,&space;coef[N]&space;=&space;C_0$

## PolyEval

 doublepolyEval( double x const double* coef int N )
Evaluates polynomial of degree N

## Example:

The following code computes solutions to the polynomial
$f(x)&space;=&space;3&space;+&space;2x&space;+&space;1x^2$
```#include <stdio.h>
#include <codecogs/maths/approximation/polynomial/poly_eval.h>

int main()
{
using namespace Maths::Algebra::Polynomial;
static double A[] = { 1,2,3 };
for(int x=2;x<=5;x++)
printf("\n polyEval(%d, A, 2)=%.1lf", x, polyEval(x, A, 2));

return 0;
}```

## Output:

```polyEval(2, A, 2)=11.0
polyEval(3, A, 2)=18.0
polyEval(4, A, 2)=27.0
polyEval(5, A, 2)=38.0```

## References:

Cephes Math Library Release 2.1: December, 1988

### Note

In the interest of speed, there are no checks for out of bounds arithmetic.

### Parameters

 x main variant coef array of coefficients coef[0..N] in reverse order N degree of polynomial, also one less that number of coefficients supplied.

### Authors

Stephen L. Moshier Copyright 1984, 1987, 1988
Documentation by Will Bateman (August 2005)
##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.

## PolyEval1

 doublepolyEval1( double x const double* coef int N )
Evaluates polynomial of degree N, where the coefficient $\inline&space;&space;C_N=1.0$. i.e. coef[0] = 1.0,
$y&space;=&space;C_0&space;+&space;C_1&space;x&space;+&space;C_2&space;x^2&space;+&space;...&space;+&space;x^N$

## Example:

The following code computes solutions to the polynomial
$f(x)&space;=&space;4&space;-&space;5x&space;+&space;x^2$
```#include <stdio.h>
#include <codecogs/maths/approximation/polynomial/poly_eval.h>

int main()
{
using namespace Algebra::Polynomial;
static double A[] = { -5, 4 };
for(int x=2;x<=5;x++)
printf("\n polyEval1(%d, A, 2)=%.1lf", x, polyEval(x, A, 2));

return 0;
}```

## Output:

```polyEval1(2, A, 2)=-2.0
polyEval1(3, A, 2)=-2.0
polyEval1(4, A, 2)=0.0
polyEval1(5, A, 2)=4.0```

## References:

Cephes Math Library Release 2.1: December, 1988

### Note

In the interest of speed, there are no checks for out of bounds arithmetic.

### Parameters

 x main variant coef array of coefficients coef[0..N-1] in reverse order N degree of polynomial, also number of coefficients supplied. Must be 2 or more.

### Authors

Stephen L. Moshier Copyright 1984, 1987, 1988
Documentation by Will Bateman (August 2005)
##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.