# CFLib.org – Common Function Library Project

## Polynomial(x, a1, a0[, a...])

##### Last updated July 18, 2001

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Horner's method, evaluates for given value of x for a polynomial in the form y = an*x^n + an-1*x^(n-1) + an-2*x^(n-2) + ... + a1 * x + a0

Supply as many coefficients as necessary (two required) for each decreasing power of x, using 0 for missing terms.

Return Values:
Returns a simple value.

Example:

``````<CFSET x = -2>
<CFSET a4 = 2>
<CFSET a3 = 0>
<CFSET a2 = -3>
<CFSET a1 = 3>
<CFSET a0 = -4>
<CFOUTPUT>
Given x = -2, a4 = 2, a3 = 0, a2 = -3, a1 = 3, a0 = -4
Polynomial(-2, 2, 0, -3, 3, -4) is #Polynomial(-2, 2, 0, -3, 3, -4)#
</CFOUTPUT>
``````

Parameters:

Name Description Required
x Any real value. Yes
a1 Real coefficient of highest power of x. Yes
a0 Real coefficient of second-highest power of x. Yes

Full UDF Source:

``````/**
* Evaluates the Polynomial in the form y = an * x^n + a(n-1) * x^(n-1) + ... + a1 * x + a0 for a given value of x.
*
* @param x      Any real value.
* @param a1      Real coefficient of highest power of x.
* @param a0      Real coefficient of second-highest power of x.
* @return Returns a simple value.
* @author Joel Cox (jlcox@goodyear.com)
* @version 1.0, July 18, 2001
*/
function Polynomial(x, a1, a0)
{
var RetVal = a1 * x + a0;
var arg_count = ArrayLen(Arguments);
var opt_arg = 4;
for( ; opt_arg LTE arg_count; opt_arg = opt_arg + 1 )
{
RetVal = RetVal * x + Arguments[opt_arg];
}
return(RetVal);
}
``````

### Search CFLib.org Raymond Camden added
QueryDeleteRows
November 04, 2017 Leigh added
May 11, 2016 Raymond Camden added
stripHTML
May 10, 2016 Kevin Cotton added
date2ExcelDate
May 05, 2016 Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson