DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
polynomial-derivative.cpp
1 
14 
15 
16 #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