mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
45 lines
1.5 KiB
C++
45 lines
1.5 KiB
C++
#include "cartesian_function.h"
|
|
|
|
namespace Graph {
|
|
|
|
CartesianFunction::CartesianFunction(const char * text, KDColor color) :
|
|
Shared::Function(text, color),
|
|
m_displayDerivative(false)
|
|
{
|
|
}
|
|
|
|
bool CartesianFunction::displayDerivative() {
|
|
return m_displayDerivative;
|
|
}
|
|
|
|
void CartesianFunction::setDisplayDerivative(bool display) {
|
|
m_displayDerivative = display;
|
|
}
|
|
|
|
double CartesianFunction::approximateDerivative(double x, Poincare::Context * context) const {
|
|
Poincare::Complex<double> abscissa = Poincare::Complex<double>::Float(x);
|
|
Poincare::Expression * args[2] = {expression(context), &abscissa};
|
|
Poincare::Derivative derivative(args, true);
|
|
/* TODO: when we will simplify derivative, we might want to simplify the
|
|
* derivative here. However, we might want to do it once for all x (to avoid
|
|
* lagging in the derivative table. */
|
|
return derivative.approximateToScalar<double>(*context);
|
|
}
|
|
|
|
double CartesianFunction::sumBetweenBounds(double start, double end, Poincare::Context * context) const {
|
|
Poincare::Complex<double> x = Poincare::Complex<double>::Float(start);
|
|
Poincare::Complex<double> y = Poincare::Complex<double>::Float(end);
|
|
Poincare::Expression * args[3] = {expression(context), &x, &y};
|
|
Poincare::Integral integral(args, true);
|
|
/* TODO: when we will simplify integral, we might want to simplify the
|
|
* integral here. However, we might want to do it once for all x (to avoid
|
|
* lagging in the derivative table. */
|
|
return integral.approximateToScalar<double>(*context);
|
|
}
|
|
|
|
char CartesianFunction::symbol() const {
|
|
return 'x';
|
|
}
|
|
|
|
}
|