Polynomial

Polynomial is a C++ class facilitating the evaluation of polynomials of a single indeterminate.

For example: the following code evaluates f(x) = 2x3 – 3x2 + 4x + 1 for values of x between -10 and 10.

include "Polynomial.h"
#include <iostream>
using namespace std;
using namespace Storage_B::Polynomials;
int main()
{
// Create a third degree polynomial: 2x^3 - 3x^2 + 4x + 1
double c[4];
c[0] = 1.0;
c[1] = 4.0;
c[2] = -3.0;
c[3] = 2.0;
Polynomial<double> poly(c, 3);
// evaluate the polynomial for a range of values
for (auto x = -10.0 ; x <= 10.0; x = x + 1.0)
{
cout << "poly(" << x << ") = " << poly(x) << endl;
}
return 0;
}

GitHub: Polynomial

Download ZIP

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

All trademarks and copyrights on this page are owned by their respective owners. Quotes from linked articles are probably the property of the publications linked or the property of the person(s) quoted. The rest © 2001- 2025 by James A. Chappell (chappell@amon-hen.com)