DGtal  0.9.3beta
polynomial-derivative.cpp
1 
14 #include <iostream>
17 #include <string>
18 #include <sstream>
19 #include "DGtal/math/MPolynomial.h"
20 #include "DGtal/io/readers/MPolynomialReader.h"
22 
24 
25 using namespace DGtal;
26 
28 
29 void usage( int, char** argv )
30 {
31  std::cerr << "Usage: " << argv[ 0 ] << " <P>" << std::endl;
32  std::cerr << "\t - computes the first and second derivative of the given polynomial P (in one variable)." << std::endl;
33 }
34 
38 int main( int argc, char** argv )
39 {
40  if ( argc < 2 )
41  {
42  usage( argc, argv );
43  return 1;
44  }
45 
47  typedef double Ring;
48  typedef MPolynomial<1, Ring> MyPolynomial;
50 
52  std::string polynomialString( argv[ 1 ] );
53  std::istringstream polynomialIStream( polynomialString );
54  MyPolynomial P;
55  polynomialIStream >> P;
56  MyPolynomial P1 = derivative<0>( P );
57  MyPolynomial P2 = derivative<0>( P1 );
58  std::cout << "P(X_0) = " << P << std::endl;
59  std::cout << "P'(X_0) = " << P1 << std::endl;
60  std::cout << "P''(X_0) = " << P2 << std::endl;
62  return 0;
63 }
64 
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field...
Definition: MPolynomial.h:58
DGtal is the top-level namespace which contains all DGtal functions and types.