mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/graph] Use the poincare derivative calculation to compute function
derivative Change-Id: I2b4d9b443935ad789e898e253a22f9d2ab652b6a
This commit is contained in:
@@ -2,6 +2,5 @@
|
||||
|
||||
constexpr int Constant::FloatBufferSizeInScientificMode;
|
||||
constexpr int Constant::NumberOfDigitsInMantissaInScientificMode;
|
||||
constexpr int Constant::NumberOfDigitsInMantissaForDerivativeNumberInScientificMode;
|
||||
constexpr int Constant::FloatBufferSizeInDecimalMode;
|
||||
constexpr int Constant::NumberOfDigitsInMantissaInDecimalMode;
|
||||
|
||||
@@ -5,7 +5,6 @@ class Constant {
|
||||
public:
|
||||
constexpr static int FloatBufferSizeInScientificMode = 14;
|
||||
constexpr static int NumberOfDigitsInMantissaInScientificMode = 7;
|
||||
constexpr static int NumberOfDigitsInMantissaForDerivativeNumberInScientificMode = 3;
|
||||
constexpr static int FloatBufferSizeInDecimalMode = 11;
|
||||
constexpr static int NumberOfDigitsInMantissaInDecimalMode = 4;
|
||||
};
|
||||
|
||||
@@ -83,11 +83,11 @@ float Function::evaluateAtAbscissa(float x, Context * context) const {
|
||||
}
|
||||
|
||||
float Function::approximateDerivative(float x, Context * context) const {
|
||||
float functionPlus = evaluateAtAbscissa(x + k_epsilon, context);
|
||||
float functionMinus = evaluateAtAbscissa(x - k_epsilon, context);
|
||||
float growthRate = (functionPlus - functionMinus)/(2*k_epsilon);
|
||||
growthRate = roundf(growthRate/k_precision)*k_precision;
|
||||
return growthRate;
|
||||
Float abscissa = Float(x);
|
||||
Expression * args[2] = {m_expression, &abscissa};
|
||||
Derivative derivative = Derivative();
|
||||
derivative.setArgument(args, 2, true);
|
||||
return derivative.approximate(*context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ void GraphController::reloadBannerView() {
|
||||
buffer[1] = '\'';
|
||||
App * graphApp = (Graph::App *)app();
|
||||
float y = f->approximateDerivative(m_cursor.x(), graphApp->localContext());
|
||||
Float(y).convertFloatToText(buffer+8, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaForDerivativeNumberInScientificMode);
|
||||
Float(y).convertFloatToText(buffer+8, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
|
||||
m_bannerView.setLegendAtIndex(buffer, 2);
|
||||
}
|
||||
m_bannerView.layoutSubviews();
|
||||
|
||||
@@ -161,7 +161,7 @@ void ValuesController::willDisplayCellAtLocation(TableViewCell * cell, int i, in
|
||||
float x = m_interval.element(j-1);
|
||||
App * graphApp = (Graph::App *)app();
|
||||
if (isDerivativeColumn(i)) {
|
||||
Float(function->approximateDerivative(x, graphApp->localContext())).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaForDerivativeNumberInScientificMode);
|
||||
Float(function->approximateDerivative(x, graphApp->localContext())).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
|
||||
} else {
|
||||
Float(function->evaluateAtAbscissa(x, graphApp->localContext())).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user