24 if (symbolName ==
'x') {
34 Expression * e = Expression::shallowReduce(context, angleUnit);
38 #if MATRIX_EXACT_REDUCING 48 Expression * Derivative::templatedApproximate(Context& context, AngleUnit angleUnit)
const {
51 VariableContext<T> xContext = VariableContext<T>(
'x', &context);
54 T x = xInput->type() ==
Type::Complex ?
static_cast<Complex<T> *
>(xInput)->toScalar() :
NAN;
57 xContext.setExpressionForSymbolName(&e, &xSymbol, xContext);
59 T functionValue = fInput->type() ==
Type::Complex ?
static_cast<Complex<T> *
>(fInput)->toScalar() :
NAN;
68 T h = k_minInitialRate;
70 result = riddersApproximation(xContext, angleUnit, x, h, &error);
86 T Derivative::growthRateAroundAbscissa(
T x,
T h, VariableContext<T> xContext, AngleUnit angleUnit)
const {
89 xContext.setExpressionForSymbolName(&e, &xSymbol, xContext);
91 T expressionPlus = fInput->type() ==
Type::Complex ?
static_cast<Complex<T> *
>(fInput)->toScalar() :
NAN;
94 xContext.setExpressionForSymbolName(&e, &xSymbol, xContext);
96 T expressionMinus = fInput->type() ==
Type::Complex ?
static_cast<Complex<T> *
>(fInput)->toScalar() :
NAN;
98 return (expressionPlus - expressionMinus)/(2*h);
102 T Derivative::riddersApproximation(VariableContext<T> xContext, AngleUnit angleUnit,
T x,
T h,
T * error)
const {
112 volatile T temp = x+h;
117 for (
int i = 0; i < 10; i++) {
118 for (
int j = 0; j < 10; j++) {
122 a[0][0] = growthRateAroundAbscissa(x, hh, xContext, angleUnit);
126 for (
int i = 1; i < 10; i++) {
127 hh /= k_rateStepSize;
129 volatile T temp = x+hh;
131 a[0][i] = growthRateAroundAbscissa(x, hh, xContext, angleUnit);
132 T fac = k_rateStepSize*k_rateStepSize;
134 for (
int j = 1; j < 10; j++) {
135 a[j][i] = (a[j-1][i]*fac-a[j-1][i-1])/(fac-1);
136 fac = k_rateStepSize*k_rateStepSize*fac;
146 if (
std::fabs(a[i][i]-a[i-1][i-1]) > 2*(*error)) {
Expression * replaceWith(Expression *newOperand, bool deleteAfterReplace=true)
Expression * approximate(Context &context, AngleUnit angleUnit=AngleUnit::Default) const
const Expression * m_operands[T]
Type type() const override
static Complex< T > Float(T x)
Expression * clone() const override
const Expression * operand(int i) const
virtual int polynomialDegree(char symbolName) const
int polynomialDegree(char symbolName) const override