DGtal  1.4.beta
math/polynomial-derivative.cpp

Computes the first and second derivative of the given polynomial P (in one variable).

See also
Computing partial derivatives and Input and output for multivariate polynomials
* $ ./examples/math/polynomial-derivative "1+x+x^2-3*x^4"
* P(X_0)   = (1 + 1 X_0 + 1 X_0^2 + -3 X_0^4)
* P'(X_0)  = (1 + 2 X_0 + -12 X_0^3)
* P''(X_0) = (2 + -36 X_0^2)
* $ ./examples/math/polynomial-derivative "(2 + -36 X_0^2)"
* P(X_0)   = (2 + -36 X_0^2)
* P'(X_0)  = -72 X_0
* P''(X_0) = -72
* 
#include <iostream>
#include <string>
#include <sstream>
#include "DGtal/math/MPolynomial.h"
#include "DGtal/io/readers/MPolynomialReader.h"
using namespace DGtal;
void usage( int, char** argv )
{
std::cerr << "Usage: " << argv[ 0 ] << " <P>" << std::endl;
std::cerr << "\t - computes the first and second derivative of the given polynomial P (in one variable)." << std::endl;
}
int main( int argc, char** argv )
{
if ( argc < 2 )
{
usage( argc, argv );
return 1;
}
typedef double Ring;
typedef MPolynomial<1, Ring> MyPolynomial;
std::string polynomialString( argv[ 1 ] );
std::istringstream polynomialIStream( polynomialString );
MyPolynomial P;
polynomialIStream >> P;
MyPolynomial P1 = derivative<0>( P );
MyPolynomial P2 = derivative<0>( P1 );
std::cout << "P(X_0) = " << P << std::endl;
std::cout << "P'(X_0) = " << P1 << std::endl;
std::cout << "P''(X_0) = " << P2 << std::endl;
return 0;
}
void usage(int, char **argv)
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)