Example of polynom read from user input.
- See also
- Multivariate polynomials
* $ ./examples/math/polynomial-read
* Type any multi-variate polynomial, then press return.
* Examples: xyz^3-4yz, (x+y+z)*(x-y-z)^2.
* (x-3)^2 + (y-2)^2 - 4
* Ok : ((9 + -4 X_1 + 1 X_1^2) + -6 X_0 + 1 X_0^2)
*
#include <iostream>
#include <iomanip>
#include <sstream>
#include "DGtal/base/Common.h"
#include "DGtal/math/MPolynomial.h"
#include "DGtal/io/readers/MPolynomialReader.h"
using namespace std;
{
typedef double Ring;
MPolynomial<3,Ring,std::allocator<Ring> > P;
MPolynomialReader<3,Ring> reader;
string str;
std::cout << "Type any multi-variate polynomial, then press return." << std::endl
<< "Examples: xyz^3-4yz, (x+y+z)*(x-y-z)^2." << std::endl;
do {
getline( cin, str );
if ( cin.good() && ( ! str.empty() ) )
{
std::string::const_iterator iter
= reader.read( P, str.begin(), str.end() );
bool ok = iter == str.end();
if ( ! ok )
{
std::cerr << "ERROR: I read only <"
<< str.substr( 0, iter - str.begin() )
<< ">, and I built P=" << P << std::endl;
}
std::cout << (ok ? "Ok : " : "Err: ") << P << std::endl;
}
} while ( ! str.empty() );
return 0;
}
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)