mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Change Expression::getVariables to get symbols with variable
sizes
This commit is contained in:
@@ -14,6 +14,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
Poincare::Expression standardForm(Poincare::Context * context) const;
|
||||
constexpr static int k_maxVariableSize = 10;
|
||||
private:
|
||||
void tidyStandardForm();
|
||||
mutable Poincare::Expression m_standardForm;
|
||||
|
||||
@@ -80,7 +80,7 @@ bool EquationStore::haveMoreApproximationSolutions(Context * context) {
|
||||
}
|
||||
|
||||
void EquationStore::approximateSolve(Poincare::Context * context) {
|
||||
assert(m_variables[0] != 0 && m_variables[1] == 0);
|
||||
assert(m_variables[0][0] != 0 && m_variables[1][0] == 0);
|
||||
assert(m_type == Type::Monovariable);
|
||||
m_numberOfSolutions = 0;
|
||||
double start = m_intervalApproximateSolutions[0];
|
||||
@@ -100,17 +100,20 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) {
|
||||
tidySolution();
|
||||
|
||||
/* 0- Get unknown variables */
|
||||
m_variables[0] = 0;
|
||||
m_variables[0][0] = 0;
|
||||
int numberOfVariables = 0;
|
||||
for (int i = 0; i < numberOfDefinedModels(); i++) {
|
||||
const Expression e = definedModelAtIndex(i)->standardForm(context);
|
||||
if (e.isUninitialized() || e.type() == ExpressionNode::Type::Undefined) {
|
||||
return Error::EquationUndefined;
|
||||
}
|
||||
numberOfVariables = definedModelAtIndex(i)->standardForm(context).getVariables(*context, Symbol::isVariableSymbol, m_variables);
|
||||
if (numberOfVariables < 0) {
|
||||
numberOfVariables = definedModelAtIndex(i)->standardForm(context).getVariables(*context, Symbol::isVariableSymbol, m_variables, Equation::k_maxVariableSize);
|
||||
if (numberOfVariables == -1) {
|
||||
return Error::TooManyVariables;
|
||||
}
|
||||
/*if (numberOfVariables == -2) {
|
||||
return Error::VariableNameTooLong;
|
||||
}*/
|
||||
}
|
||||
|
||||
/* 1- Linear System? */
|
||||
@@ -150,9 +153,8 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) {
|
||||
} else {
|
||||
/* 2- Polynomial & Monovariable? */
|
||||
assert(numberOfVariables == 1 && numberOfDefinedModels() == 1);
|
||||
const char x[] = {m_variables[0], 0};
|
||||
Expression polynomialCoefficients[Expression::k_maxNumberOfPolynomialCoefficients];
|
||||
int degree = definedModelAtIndex(0)->standardForm(context).getPolynomialReducedCoefficients(x, polynomialCoefficients, *context, preferences->angleUnit());
|
||||
int degree = definedModelAtIndex(0)->standardForm(context).getPolynomialReducedCoefficients(m_variables[0], polynomialCoefficients, *context, preferences->angleUnit());
|
||||
if (degree == 2) {
|
||||
/* Polynomial degree <= 2*/
|
||||
m_type = Type::PolynomialMonovariable;
|
||||
@@ -189,7 +191,9 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) {
|
||||
|
||||
EquationStore::Error EquationStore::resolveLinearSystem(Expression exactSolutions[k_maxNumberOfExactSolutions], Expression coefficients[k_maxNumberOfEquations][Expression::k_maxNumberOfVariables], Expression constants[k_maxNumberOfEquations], Context * context) {
|
||||
Preferences::AngleUnit angleUnit = Preferences::sharedPreferences()->angleUnit();
|
||||
int n = strlen(m_variables); // n unknown variables
|
||||
// n unknown variables
|
||||
int n = 0;
|
||||
while (m_variables[n++][0] != 0) {}
|
||||
int m = numberOfDefinedModels(); // m equations
|
||||
/* Create the matrix (A | b) for the equation Ax=b */
|
||||
Matrix Ab;
|
||||
|
||||
@@ -84,7 +84,7 @@ private:
|
||||
|
||||
Equation m_equations[k_maxNumberOfEquations];
|
||||
Type m_type;
|
||||
char m_variables[Poincare::Expression::k_maxNumberOfVariables+1];
|
||||
char m_variables[Poincare::Expression::k_maxNumberOfVariables+1][Equation::k_maxVariableSize];
|
||||
int m_numberOfSolutions;
|
||||
Poincare::Layout m_exactSolutionExactLayouts[k_maxNumberOfApproximateSolutions];
|
||||
Poincare::Layout m_exactSolutionApproximateLayouts[k_maxNumberOfExactSolutions];
|
||||
|
||||
Reference in New Issue
Block a user