File indexing completed on 2024-05-12 03:41:58

0001 /*************************************************************************************
0002  *  Copyright (C) 2014 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com>      *
0003  *                                                                                   *
0004  *  This program is free software; you can redistribute it and/or                    *
0005  *  modify it under the terms of the GNU General Public License                      *
0006  *  as published by the Free Software Foundation; either version 2                   *
0007  *  of the License, or (at your option) any later version.                           *
0008  *                                                                                   *
0009  *  This program is distributed in the hope that it will be useful,                  *
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
0012  *  GNU General Public License for more details.                                     *
0013  *                                                                                   *
0014  *  You should have received a copy of the GNU General Public License                *
0015  *  along with this program; if not, write to the Free Software                      *
0016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
0017  *************************************************************************************/
0018 
0019 #ifndef MATRIXCOMMANDS_H
0020 #define MATRIXCOMMANDS_H
0021 
0022 #include "builtinmethods.h"
0023 
0024 namespace Analitza {
0025 class Expression;
0026 }
0027 
0028 /**
0029  * \class MatrixCommand
0030  * 
0031  * \brief Implements the \"matrix\" command.
0032  * 
0033  * MatrixCommand constructs a matrix by two ways:
0034  * 
0035  * The first way creates a matrix filled with a fixed value. 
0036  * \code matrix(3) \endcode 
0037  * constructs a square 3x3 matrix filled with zeros.
0038  * 
0039  * \code matrix(4,5) \endcode 
0040  * constructs a 4x5 matrix filled with zeros.
0041  * 
0042  * \code matrix(6,7, 0.5) \endcode 
0043  * constructs a 6x7 matrix filled with the value 0.5.
0044  * 
0045  * The second way creates a matrix by given vectors or matrixrow elements.
0046  * \code matrix(vector{1,3}, vector{4,5}) \endcode 
0047  * constructs a matrix with two column vectors:
0048  * [1 4]
0049  * [3 5]
0050  * 
0051  * \code matrix(matrixrow{1,3}, matrixrow{4,5}) \endcode 
0052  * constructs a matrix with two matrixrow elements:
0053  * [1 3]
0054  * [4 5]
0055  *
0056  */
0057 
0058 class MatrixCommand: public Analitza::FunctionDefinition
0059 {
0060 public:
0061     virtual Analitza::Expression operator()(const QList< Analitza::Expression >& args) override;
0062     
0063     static const QString id;
0064     static const Analitza::ExpressionType type;
0065 };
0066 
0067 /**
0068  * \class IdentityMatrixCommand
0069  * 
0070  * \brief Implements the \"identitymatrix\" command.
0071  * 
0072  * IdentityMatrixCommand constructs a identitymatrix.
0073  * For example:
0074  * \code matrix(2) \endcode
0075  * \code matrix { matrixrow { 1, 0 }, matrixrow { 1, 0 } } \endcode
0076  * 
0077  */
0078 
0079 class IdentityMatrixCommand: public Analitza::FunctionDefinition
0080 {
0081 public:
0082     virtual Analitza::Expression operator()(const QList< Analitza::Expression >& args) override;
0083 
0084     static const QString id;
0085     static const Analitza::ExpressionType type;
0086 };
0087 
0088 /**
0089  * \class DiagonalMatrixCommand
0090  * 
0091  * \brief Implements the \"diag\" command.
0092  * 
0093  * DiagonalMatrixCommand can be used to construct a diagonal matrix and also 
0094  * to get the diagonal part of a matrix.
0095  * 
0096  * There are two ways to construct a diagonal matrix:
0097  *
0098  * The first way creates the diagonal part out of the parameters.
0099  * \code diag(1,2,3) \endcode 
0100  * constructs the 3x3 diagonal matrix:
0101  * [1 0 0]
0102  * [0 2 0]
0103  * [0 0 3]
0104  * 
0105  * The second way uses a vector as the diagonal part:
0106  * \code diag(vector{1,2,3}) \endcode 
0107  * is equivalent to 
0108  * \code diag(1,2,3) \endcode 
0109  *
0110  * There are two ways to get the diagonal part of a matrix, also both always 
0111  * return a vector that contains the requested diagonal part.
0112  * 
0113  * The first way always get the principal diagonal of the a given matrix.
0114  * \code diag(matrix{matrixrow{1,2}, matrixrow{3,4}}) \endcode 
0115  * returns 
0116  * \code vector{1,4} \endcode 
0117  * 
0118  * The second way returns a vector of the elements on the nth diagonal of 
0119  * a given matrix.
0120  * 
0121  * \code diag(A, n) \endcode 
0122  * where n>0 means is above the main diagonal of A and n<0 is below the main 
0123  * diagonal.
0124  * 
0125  * Examples:
0126  * 
0127  * \code diag(matrix{matrixrow{1,2}, matrixrow{3,4}}, 0) \endcode 
0128  * is equivalent to 
0129  * \code diag(matrix{matrixrow{1,2}, matrixrow{3,4}}) \endcode 
0130  * 
0131  * \code diag(matrix{matrixrow{1,2}, matrixrow{3,4}}, 1) \endcode 
0132  * returns 
0133  * \code vector{2} \endcode
0134  *
0135  * \code diag(matrix{matrixrow{1,2}, matrixrow{3,4}}, -1) \endcode 
0136  * returns 
0137  * \code vector{3} \endcode 
0138  * 
0139  */
0140 
0141 class DiagonalMatrixCommand: public Analitza::FunctionDefinition
0142 {
0143 public:
0144     virtual Analitza::Expression operator()(const QList< Analitza::Expression >& args) override;
0145 
0146     static const QString id;
0147     static const Analitza::ExpressionType type;
0148 };
0149 
0150 /**
0151  * \class TridiagonalMatrixCommand
0152  * 
0153  * \brief Implements the \"tridiag\" command.
0154  * 
0155  * TridiagonalMatrixCommand constructs a tridiagonal matrix.
0156  * 
0157  * \code tridiag(a, b, c, n) \endcode
0158  * where b is in the main diagonal, a is below the main diagonal, 
0159  * c is above the main diagonal and n is the size of the matrix.
0160  * 
0161  */
0162 
0163 class TridiagonalMatrixCommand: public Analitza::FunctionDefinition
0164 {
0165 public:
0166     virtual Analitza::Expression operator()(const QList< Analitza::Expression >& args) override;
0167 
0168     static const QString id;
0169     static const Analitza::ExpressionType type;
0170 };
0171 
0172 //TODO random matrix (default 0,1 ... but you can set min and max vals)
0173 
0174 #endif // MATRIXCOMMANDS_H