mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/sequence] Improve method to evaluate sequence at abscissa
Change-Id: I04dc0e960adde25d95ce80cc7e43fb0ec5c9b625
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "sequence.h"
|
||||
#include "local_context.h"
|
||||
#include "../../poincare/src/layout/baseline_relative_layout.h"
|
||||
#include "../../poincare/src/layout/string_layout.h"
|
||||
#include <string.h>
|
||||
@@ -172,4 +173,60 @@ bool Sequence::isDefined() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float Sequence::evaluateAtAbscissa(float x, Poincare::Context * context) const {
|
||||
float n = roundf(x);
|
||||
switch (m_type) {
|
||||
case Type::Explicite:
|
||||
if (n < 0) {
|
||||
return NAN;
|
||||
}
|
||||
return Shared::Function::evaluateAtAbscissa(n, context);
|
||||
case Type::SingleRecurrence:
|
||||
{
|
||||
if (n < 0) {
|
||||
return NAN;
|
||||
}
|
||||
if (n == 0) {
|
||||
return m_firstInitialConditionExpression->approximate(*context);
|
||||
}
|
||||
float un = m_firstInitialConditionExpression->approximate(*context);
|
||||
LocalContext subContext = LocalContext(context);
|
||||
Poincare::Symbol nSymbol = Poincare::Symbol(symbol());
|
||||
for (int i = 0; i < n; i++) {
|
||||
subContext.setSequenceRankValue(un, 0);
|
||||
Poincare::Complex e = Poincare::Complex::Float(i);
|
||||
subContext.setExpressionForSymbolName(&e, &nSymbol);
|
||||
un = m_expression->approximate(subContext);
|
||||
}
|
||||
return un;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (n < 0) {
|
||||
return NAN;
|
||||
}
|
||||
if (n == 0) {
|
||||
return m_firstInitialConditionExpression->approximate(*context);
|
||||
}
|
||||
if (n == 1) {
|
||||
return m_secondInitialConditionExpression->approximate(*context);
|
||||
}
|
||||
float un = m_firstInitialConditionExpression->approximate(*context);
|
||||
float un1 = m_secondInitialConditionExpression->approximate(*context);
|
||||
LocalContext subContext = LocalContext(context);
|
||||
Poincare::Symbol nSymbol = Poincare::Symbol(symbol());
|
||||
for (int i = 0; i < n-1; i++) {
|
||||
subContext.setSequenceRankValue(un, 0);
|
||||
subContext.setSequenceRankValue(un1, 1);
|
||||
Poincare::Complex e = Poincare::Complex::Float(i);
|
||||
subContext.setExpressionForSymbolName(&e, &nSymbol);
|
||||
un = un1;
|
||||
un1 = m_expression->approximate(subContext);
|
||||
}
|
||||
return un1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user