DGtal  0.9.3beta
polynomial2-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(x,y)>" << std::endl;
32  std::cerr << "\t - computes the first and second derivatives of the given polynomial P (in two variables)." << 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<2, Ring> MyPolynomial;
50 
52  std::string polynomialString( argv[ 1 ] );
53  std::istringstream polynomialIStream( polynomialString );
54  MyPolynomial P;
55  polynomialIStream >> P;
56  MyPolynomial P1_0 = derivative<0>( P );
57  MyPolynomial P2_0 = derivative<0>( P1_0 );
58  MyPolynomial P0_1 = derivative<1>( P );
59  MyPolynomial P0_2 = derivative<1>( P0_1 );
60  MyPolynomial P1_1 = derivative<1>( P1_0 );
61  MyPolynomial P1_1b= derivative<0>( P0_1 );
62  std::cout << "P(X_0,X_1) = " << P << std::endl;
63  std::cout << "dP/dX_0(X_0,X_1) = " << P1_0 << std::endl;
64  std::cout << "dP/dX_1(X_0,X_1) = " << P0_1 << std::endl;
65  std::cout << "d/dX_1 dP/dX_0(X_0,X_1) = " << P1_1 << std::endl;
66  std::cout << "d/dX_0 dP/dX_1(X_0,X_1) = " << P1_1b << std::endl;
67  std::cout << "d/dX_0 dP/dX_0(X_0,X_1) = " << P2_0 << std::endl;
68  std::cout << "d/dX_1 dP/dX_1(X_0,X_1) = " << P0_2 << std::endl;
70  return 0;
71 }
72 
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.