[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [analitza/aucahuasi/matrixctrs] analitza: tridiag(a, b, c, n) constructs a tridiagonal nxn-matrix (a
From: Percy_Camilo_Triveño_Aucahuasi <percy.camilo.ta () gmail ! com>
Date: 2014-05-01 0:13:54
Message-ID: E1WfedO-0000lm-3I () scm ! kde ! org
[Download RAW message or body]
Git commit bbbb289471cf87a04716d861c64e948b214d3d4c by Percy Camilo Triveño \
Aucahuasi. Committed on 01/05/2014 at 00:13.
Pushed by aucahuasi into branch 'aucahuasi/matrixctrs'.
tridiag(a, b, c, n) constructs a tridiagonal nxn-matrix (a below diag, b main diag, c \
above diag)
M +1 -0 analitza/analyzer.cpp
M +61 -3 analitza/matrixbuiltinmethods.cpp
M +11 -0 analitza/matrixbuiltinmethods.h
M +2 -1 analitza/tests/matrixtest.cpp
http://commits.kde.org/analitza/bbbb289471cf87a04716d861c64e948b214d3d4c
diff --git a/analitza/analyzer.cpp b/analitza/analyzer.cpp
index 3646d3b..8499bb2 100644
--- a/analitza/analyzer.cpp
+++ b/analitza/analyzer.cpp
@@ -158,6 +158,7 @@ void Analyzer::registerBuiltinMethods()
m_builtin.insertFunction(MatrixConstructor::id, MatrixConstructor::type, new \
MatrixConstructor); m_builtin.insertFunction(IdentityMatrixConstructor::id, \
IdentityMatrixConstructor::type, new IdentityMatrixConstructor); \
m_builtin.insertFunction(DiagonalMatrixConstructor::id, \
DiagonalMatrixConstructor::type, new DiagonalMatrixConstructor); \
+ m_builtin.insertFunction(TridiagonalMatrixConstructor::id, \
TridiagonalMatrixConstructor::type, new TridiagonalMatrixConstructor); }
void Analyzer::setExpression(const Expression & e)
diff --git a/analitza/matrixbuiltinmethods.cpp b/analitza/matrixbuiltinmethods.cpp
index eb7df94..3c04ac4 100644
--- a/analitza/matrixbuiltinmethods.cpp
+++ b/analitza/matrixbuiltinmethods.cpp
@@ -165,9 +165,9 @@ Expression IdentityMatrixConstructor::operator()(const QList< \
Analitza::Expressi {
if (args.first().isReal())
{
- const Analitza::Cn *nobj = static_cast<const Analitza::Cn*>(args.at(0).tree());
+ const Analitza::Cn *nobj = static_cast<const \
Analitza::Cn*>(args.first().tree());
- if (nobj->isInteger())
+ if (!nobj->isInteger() && nobj->value() > 0)
{
const int n = nobj->value();
@@ -189,7 +189,7 @@ Expression IdentityMatrixConstructor::operator()(const QList< \
Analitza::Expressi ret.setTree(matrix);
}
else
- ret.addError("bad format of arg:must be integer");
+ ret.addError("bad format of arg:must be positve integer");
}
}
else
@@ -282,5 +282,63 @@ Expression DiagonalMatrixConstructor::operator()(const QList< \
Analitza::Expressi return ret;
}
+/// bands
+
+const QString TridiagonalMatrixConstructor::id = QString("tridiag");
+const ExpressionType TridiagonalMatrixConstructor::type = MatrixConstructor::type;
+
+Expression TridiagonalMatrixConstructor::operator()(const QList< \
Analitza::Expression >& args) +{
+ Expression ret;
+
+ if (args.isEmpty())
+ return ret;
+
+ if (args.size() != 4)
+ {
+ ret.addError("bad number of args meust be a,b,c,n");
+
+ return ret;
+ }
+
+ const Analitza::Cn *nobj = static_cast<const Analitza::Cn*>(args.last().tree());
+
+ const int n = nobj->value();
+
+// qDebug() << "CALCLATE 1 " << n;
+
+ if (!nobj->isInteger() && n > 0)
+ {
+ ret.addError("the last arg (n) must be positve integer");
+
+ return ret;
+ }
+
+ Analitza::Matrix *matrix = new Analitza::Matrix();
+
+ for (int row = 0; row < n; ++row)
+ {
+ Analitza::MatrixRow *rowobj = new Analitza::MatrixRow(n);
+
+ for (int col= 0; col < n; ++col)
+ if (row == col + 1) // a
+ rowobj->appendBranch(args.at(0).tree()->copy());
+ else
+ if (row == col) // b
+ rowobj->appendBranch(args.at(1).tree()->copy());
+ else
+ if (row == col - 1) // c
+ rowobj->appendBranch(args.at(2).tree()->copy());
+ else
+ rowobj->appendBranch(new Analitza::Cn(0));
+
+ matrix->appendBranch(rowobj);
+ }
+
+ ret.setTree(matrix);
+
+ return ret;
+}
+
//END DiagonalMatrixConstructor
diff --git a/analitza/matrixbuiltinmethods.h b/analitza/matrixbuiltinmethods.h
index 63001fe..275a11a 100644
--- a/analitza/matrixbuiltinmethods.h
+++ b/analitza/matrixbuiltinmethods.h
@@ -114,6 +114,17 @@ public:
//END DiagonalMatrixConstructor
+//some bands contrs
+//tridiag(a, b, c, n)
+
+class TridiagonalMatrixConstructor: public Analitza::FunctionDefinition
+{
+public:
+ virtual Analitza::Expression operator()(const QList< Analitza::Expression >& args);
+
+ static const QString id;
+ static const Analitza::ExpressionType type;
+};
#endif // MATRIXBUILTINMETHODS_H
diff --git a/analitza/tests/matrixtest.cpp b/analitza/tests/matrixtest.cpp
index 67c02bd..8a8eca5 100644
--- a/analitza/tests/matrixtest.cpp
+++ b/analitza/tests/matrixtest.cpp
@@ -102,7 +102,8 @@ void MatrixTest::testBuiltinMethods()
// a->setExpression(Expression("identitymatrix(3)"));
// a->setExpression(Expression("diag(5,7,9,16)"));
// a->setExpression(Expression("diag(matrix{matrixrow{3,2,0}, matrixrow{1,4,7}, \
matrixrow{9,6,5}})"));
- a->setExpression(Expression("diag(matrix( row(6,47,8,5), row(4, 7,6,7) , row(4, \
7,56,7) , row(4, 7,8,79) ))")); +// a->setExpression(Expression("diag(matrix( \
row(6,47,8,5), row(4, 7,6,7) , row(4, 7,56,7) , row(4, 7,8,79) ))")); \
+ a->setExpression(Expression("tridiag(3, 8, 9, 5)")); qDebug() << \
a->calculate().toString(); qDebug() << a->errors();
/// GSOC info
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic