mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps] Add a function "sumBetweenBounds()" on Function (sum of terms on
Sequence, Integral on CartesianFunction)
This commit is contained in:
committed by
EmilieNumworks
parent
7ea0dbeb56
commit
cdfbc02499
@@ -26,6 +26,17 @@ double CartesianFunction::approximateDerivative(double x, Poincare::Context * co
|
||||
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';
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ public:
|
||||
bool displayDerivative();
|
||||
void setDisplayDerivative(bool display);
|
||||
double approximateDerivative(double x, Poincare::Context * context) const;
|
||||
double sumBetweenBounds(double start, double end, Poincare::Context * context) const override;
|
||||
char symbol() const override;
|
||||
private:
|
||||
bool m_displayDerivative;
|
||||
|
||||
@@ -27,11 +27,6 @@ bool TermSumController::moveCursorHorizontallyToPosition(double position) {
|
||||
return SumGraphController::moveCursorHorizontallyToPosition(std::round(position));
|
||||
}
|
||||
|
||||
double TermSumController::computeSum(double start, double end) {
|
||||
App * myApp = static_cast<App *>(app());
|
||||
return static_cast<Sequence *>(m_function)->sumOfTermsBetweenAbscissa(m_startSum, m_endSum, myApp->localContext());
|
||||
}
|
||||
|
||||
I18n::Message TermSumController::legendMessageAtStep(Step step) {
|
||||
switch(step) {
|
||||
case Step::FirstParameter:
|
||||
|
||||
@@ -14,7 +14,6 @@ public:
|
||||
const char * title() override;
|
||||
private:
|
||||
bool moveCursorHorizontallyToPosition(double position) override;
|
||||
double computeSum(double start, double end) override;
|
||||
I18n::Message legendMessageAtStep(Step step) override;
|
||||
double cursorNextStep(double position, int direction) override;
|
||||
};
|
||||
|
||||
@@ -357,7 +357,7 @@ T Sequence::approximateToNextRank(int n, SequenceContext * sqctx) const {
|
||||
}
|
||||
}
|
||||
|
||||
double Sequence::sumOfTermsBetweenAbscissa(double start, double end, Context * context) {
|
||||
double Sequence::sumBetweenBounds(double start, double end, Context * context) const {
|
||||
double result = 0.0;
|
||||
if (end-start > k_maxNumberOfTermsInSum || start + 1.0 == start) {
|
||||
return NAN;
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
return templatedApproximateAtAbscissa(x, static_cast<SequenceContext *>(context));
|
||||
}
|
||||
template<typename T> T approximateToNextRank(int n, SequenceContext * sqctx) const;
|
||||
double sumOfTermsBetweenAbscissa(double start, double end, Poincare::Context * context);
|
||||
double sumBetweenBounds(double start, double end, Poincare::Context * context) const override;
|
||||
void tidy() override;
|
||||
constexpr static int k_initialRankNumberOfDigits = 3; // m_initialRank is capped by 999
|
||||
private:
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
virtual double evaluateAtAbscissa(double x, Poincare::Context * context) const {
|
||||
return templatedApproximateAtAbscissa(x, context);
|
||||
}
|
||||
virtual double sumBetweenBounds(double start, double end, Poincare::Context * context) const = 0;
|
||||
virtual void tidy();
|
||||
private:
|
||||
constexpr static size_t k_dataLengthInBytes = (TextField::maxBufferSize()+2)*sizeof(char)+2;
|
||||
|
||||
@@ -192,7 +192,8 @@ bool SumGraphController::handleEnter() {
|
||||
return true;
|
||||
}
|
||||
m_step = (Step)((int)m_step+1);
|
||||
double sum = computeSum(m_startSum, m_endSum);
|
||||
TextFieldDelegateApp * myApp = static_cast<TextFieldDelegateApp *>(app());
|
||||
double sum = m_function->sumBetweenBounds(m_startSum, m_endSum, myApp->localContext());
|
||||
m_legendView.setSumSymbol(m_step, m_startSum, m_endSum, sum, m_function->name());
|
||||
m_legendView.setLegendMessage(I18n::Message::Default, m_step);
|
||||
m_graphView->setAreaHighlightColor(true);
|
||||
|
||||
@@ -38,7 +38,6 @@ private:
|
||||
constexpr static float k_cursorRightMarginRatio = 0.04f; // (cursorWidth/2)/graphViewWidth
|
||||
constexpr static float k_cursorBottomMarginRatio = 0.28f; // (cursorHeight/2+bannerHeigh)/graphViewHeight
|
||||
constexpr static float k_cursorLeftMarginRatio = 0.04f; // (cursorWidth/2)/graphViewWidth
|
||||
virtual double computeSum(double start, double end) = 0;
|
||||
virtual I18n::Message legendMessageAtStep(Step step) = 0;
|
||||
virtual double cursorNextStep(double position, int direction) = 0;
|
||||
Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override { return m_graphRange; }
|
||||
|
||||
Reference in New Issue
Block a user