diff options
author | Richard Braun <syn@sceen.net> | 2006-05-30 12:57:32 +0000 |
---|---|---|
committer | Richard Braun <syn@sceen.net> | 2006-05-30 12:57:32 +0000 |
commit | 2ab48b799578c6bfaa60d2703e874918e3e3005a (patch) | |
tree | a5f3b2c0c14e981ba075ff6351924da3e89672ff | |
parent | 3d937ef6781e30ad95239cc2c7d78e44589d26d8 (diff) |
Language implements LU decomposition.
-rw-r--r-- | mtxexpression.cc | 45 | ||||
-rw-r--r-- | mtxexpression.h | 3 |
2 files changed, 45 insertions, 3 deletions
diff --git a/mtxexpression.cc b/mtxexpression.cc index f18e7be..0d51f90 100644 --- a/mtxexpression.cc +++ b/mtxexpression.cc @@ -41,6 +41,7 @@ struct mtx_function MtxExpression::functions[] = {"inverse", MTXEXPRESSION_FUNCTION_INVERSE, 1}, {"transpose", MTXEXPRESSION_FUNCTION_TRANSPOSE, 1}, {"augment", MTXEXPRESSION_FUNCTION_AUGMENT, 2}, + {"lu", MTXEXPRESSION_FUNCTION_LUDECOMPOSITION, 3}, {NULL, MTXEXPRESSION_FUNCTION_NULL} }; @@ -630,8 +631,8 @@ MtxExpression::getSymbol(bool create, bool fail_if_special) const else { - MtxMatrix *matrix, *matrix2; - MtxSymbol symbol; + MtxMatrix *matrix, *matrix2, *matrix3; + MtxSymbol symbol, symbol2; MtxValue *value; /* @@ -795,6 +796,46 @@ MtxExpression::getSymbol(bool create, bool fail_if_special) const delete matrix; delete matrix2; return symbol; + + case MTXEXPRESSION_FUNCTION_LUDECOMPOSITION: + value = expressions[0]->getSymbol().getValue()->clone(); + matrix = dynamic_cast<MtxMatrix *>(value); + + if (matrix == NULL) + { + delete value; + throw MtxException("argument is not a matrix"); + } + + matrix2 = new MtxMatrix(); + matrix3 = new MtxMatrix(); + + try + { + matrix->luDecomposition(*matrix2, *matrix3); + + symbol = MtxSymbol(language, + expressions[1]->getSymbol(true).getName(), + *matrix2); + language->setSymbol(symbol); + symbol2 = MtxSymbol(language, + expressions[2]->getSymbol(true).getName(), + *matrix3); + language->setSymbol(symbol2); + } + + catch (MtxException &exception) + { + delete matrix3; + delete matrix2; + delete matrix; + throw exception; + } + + delete matrix3; + delete matrix2; + delete matrix; + return MtxSymbol(language, MtxInteger(1)); } throw MtxException("operator/function not yet implemented"); diff --git a/mtxexpression.h b/mtxexpression.h index e22dcfe..848a2a9 100644 --- a/mtxexpression.h +++ b/mtxexpression.h @@ -51,7 +51,8 @@ enum mtx_function_id MTXEXPRESSION_FUNCTION_DETERMINANT, MTXEXPRESSION_FUNCTION_INVERSE, MTXEXPRESSION_FUNCTION_TRANSPOSE, - MTXEXPRESSION_FUNCTION_AUGMENT + MTXEXPRESSION_FUNCTION_AUGMENT, + MTXEXPRESSION_FUNCTION_LUDECOMPOSITION }; /** |