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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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