1 /************************************************************************************* 2 * Copyright (C) 2014 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> * 3 * * 4 * This program is free software; you can redistribute it and/or * 5 * modify it under the terms of the GNU General Public License * 6 * as published by the Free Software Foundation; either version 2 * 7 * of the License, or (at your option) any later version. * 8 * * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 * GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program; if not, write to the Free Software * 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 17 *************************************************************************************/ 18 19 #ifndef MATRIXCOMMANDS_H 20 #define MATRIXCOMMANDS_H 21 22 #include "builtinmethods.h" 23 24 namespace Analitza { 25 class Expression; 26 } 27 28 /** 29 * \class MatrixCommand 30 * 31 * \brief Implements the \"matrix\" command. 32 * 33 * MatrixCommand constructs a matrix by two ways: 34 * 35 * The first way creates a matrix filled with a fixed value. 36 * \code matrix(3) \endcode 37 * constructs a square 3x3 matrix filled with zeros. 38 * 39 * \code matrix(4,5) \endcode 40 * constructs a 4x5 matrix filled with zeros. 41 * 42 * \code matrix(6,7, 0.5) \endcode 43 * constructs a 6x7 matrix filled with the value 0.5. 44 * 45 * The second way creates a matrix by given vectors or matrixrow elements. 46 * \code matrix(vector{1,3}, vector{4,5}) \endcode 47 * constructs a matrix with two column vectors: 48 * [1 4] 49 * [3 5] 50 * 51 * \code matrix(matrixrow{1,3}, matrixrow{4,5}) \endcode 52 * constructs a matrix with two matrixrow elements: 53 * [1 3] 54 * [4 5] 55 * 56 */ 57 58 class MatrixCommand: public Analitza::FunctionDefinition 59 { 60 public: 61 virtual Analitza::Expression operator()(const QList< Analitza::Expression >& args) override; 62 63 static const QString id; 64 static const Analitza::ExpressionType type; 65 }; 66 67 /** 68 * \class IdentityMatrixCommand 69 * 70 * \brief Implements the \"identitymatrix\" command. 71 * 72 * IdentityMatrixCommand constructs a identitymatrix. 73 * For example: 74 * \code matrix(2) \endcode 75 * \code matrix { matrixrow { 1, 0 }, matrixrow { 1, 0 } } \endcode 76 * 77 */ 78 79 class IdentityMatrixCommand: public Analitza::FunctionDefinition 80 { 81 public: 82 virtual Analitza::Expression operator()(const QList< Analitza::Expression >& args) override; 83 84 static const QString id; 85 static const Analitza::ExpressionType type; 86 }; 87 88 /** 89 * \class DiagonalMatrixCommand 90 * 91 * \brief Implements the \"diag\" command. 92 * 93 * DiagonalMatrixCommand can be used to construct a diagonal matrix and also 94 * to get the diagonal part of a matrix. 95 * 96 * There are two ways to construct a diagonal matrix: 97 * 98 * The first way creates the diagonal part out of the parameters. 99 * \code diag(1,2,3) \endcode 100 * constructs the 3x3 diagonal matrix: 101 * [1 0 0] 102 * [0 2 0] 103 * [0 0 3] 104 * 105 * The second way uses a vector as the diagonal part: 106 * \code diag(vector{1,2,3}) \endcode 107 * is equivalent to 108 * \code diag(1,2,3) \endcode 109 * 110 * There are two ways to get the diagonal part of a matrix, also both always 111 * return a vector that contains the requested diagonal part. 112 * 113 * The first way always get the principal diagonal of the a given matrix. 114 * \code diag(matrix{matrixrow{1,2}, matrixrow{3,4}}) \endcode 115 * returns 116 * \code vector{1,4} \endcode 117 * 118 * The second way returns a vector of the elements on the nth diagonal of 119 * a given matrix. 120 * 121 * \code diag(A, n) \endcode 122 * where n>0 means is above the main diagonal of A and n<0 is below the main 123 * diagonal. 124 * 125 * Examples: 126 * 127 * \code diag(matrix{matrixrow{1,2}, matrixrow{3,4}}, 0) \endcode 128 * is equivalent to 129 * \code diag(matrix{matrixrow{1,2}, matrixrow{3,4}}) \endcode 130 * 131 * \code diag(matrix{matrixrow{1,2}, matrixrow{3,4}}, 1) \endcode 132 * returns 133 * \code vector{2} \endcode 134 * 135 * \code diag(matrix{matrixrow{1,2}, matrixrow{3,4}}, -1) \endcode 136 * returns 137 * \code vector{3} \endcode 138 * 139 */ 140 141 class DiagonalMatrixCommand: public Analitza::FunctionDefinition 142 { 143 public: 144 virtual Analitza::Expression operator()(const QList< Analitza::Expression >& args) override; 145 146 static const QString id; 147 static const Analitza::ExpressionType type; 148 }; 149 150 /** 151 * \class TridiagonalMatrixCommand 152 * 153 * \brief Implements the \"tridiag\" command. 154 * 155 * TridiagonalMatrixCommand constructs a tridiagonal matrix. 156 * 157 * \code tridiag(a, b, c, n) \endcode 158 * where b is in the main diagonal, a is below the main diagonal, 159 * c is above the main diagonal and n is the size of the matrix. 160 * 161 */ 162 163 class TridiagonalMatrixCommand: public Analitza::FunctionDefinition 164 { 165 public: 166 virtual Analitza::Expression operator()(const QList< Analitza::Expression >& args) override; 167 168 static const QString id; 169 static const Analitza::ExpressionType type; 170 }; 171 172 //TODO random matrix (default 0,1 ... but you can set min and max vals) 173 174 #endif // MATRIXCOMMANDS_H 175