DGtal  1.1.0
math/polynomial-derivative.cpp

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

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"
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;
}
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
usage
void usage(int, char **argv)
Definition: approximation.cpp:64
DGtal::MPolynomial
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.
Definition: MPolynomial.h:955