]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGMatrix.h
Oct 2, 2000 JSBSim sync.
[flightgear.git] / src / FDM / JSBSim / FGMatrix.h
1 /*******************************************************************************
2
3 Header: FGMatrix.h
4 Author: Originally by Tony Peden [formatted and adapted here by Jon Berndt]
5 Date started: Unknown
6
7 HISTORY
8 --------------------------------------------------------------------------------
9 ??/??/??   TP   Created
10 03/16/2000 JSB  Added exception throwing
11
12 ********************************************************************************
13 SENTRY
14 *******************************************************************************/
15
16 #ifndef FGMATRIX_H
17 #define FGMATRIX_H
18
19 /*******************************************************************************
20 INCLUDES
21 *******************************************************************************/
22
23 #include <stdlib.h>
24 #ifdef FGFS
25 #  include <simgear/compiler.h>
26 #  ifdef FG_HAVE_STD_INCLUDES
27 #    include <fstream>
28 #    include <cmath>
29 #    include <iostream>
30 #  else
31 #    include <fstream.h>
32 #    include <math.h>
33 #    include <iostream.h>
34 #  endif
35 #else
36 #  include <fstream>
37 #  include <cmath>
38 #  include <iostream>
39 #endif
40
41 #include <string>
42
43 /*******************************************************************************
44 FORWARD DECLARATIONS
45 *******************************************************************************/
46
47 class FGColumnVector;
48
49 /*******************************************************************************
50 DECLARATION: MatrixException
51 *******************************************************************************/
52
53 using std::string;
54 using std::ostream;
55 using std::istream;
56 using std::cerr;
57 using std::endl;
58
59 class MatrixException /* :  public exception */  
60 {
61 public:
62   string Message;
63 };
64
65 /*******************************************************************************
66 DECLARATION: FGMatrix
67 *******************************************************************************/
68
69 class FGMatrix
70 {
71 protected:
72   double **data;
73
74 private:
75   unsigned int rows,cols;
76   char delim;
77   int width,prec,origin;
78   void TransposeSquare(void);
79   void TransposeNonSquare(void);
80   unsigned int rowCtr, colCtr;
81
82 public:
83   FGMatrix(unsigned int r, unsigned int c);
84   FGMatrix(const FGMatrix& A);
85   ~FGMatrix(void);
86
87   FGMatrix& operator=(const FGMatrix& A);
88   inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
89
90   FGColumnVector operator*(const FGColumnVector& Col);
91
92   unsigned int Rows(void) const;
93   unsigned int Cols(void) const;
94
95   void T(void);
96   void InitMatrix(void);
97   void InitMatrix(double value);
98
99   FGMatrix operator-(const FGMatrix& B);
100   FGMatrix operator+(const FGMatrix& B);
101   FGMatrix operator*(const FGMatrix& B);
102   FGMatrix operator/(const double scalar);
103   FGMatrix& operator<<(const float ff);
104
105   friend ostream& operator<<(ostream& os, const FGMatrix& M);
106   friend istream& operator>>(istream& is, FGMatrix& M);
107
108   void operator-=(const FGMatrix &B);
109   void operator+=(const FGMatrix &B);
110   void operator*=(const FGMatrix &B);
111   void operator*=(const double scalar);
112   void operator/=(const double scalar);
113
114   friend FGMatrix operator*(double scalar,FGMatrix& A);
115
116   void SetOParams(char delim,int width,int prec, int origin=0);
117 };
118
119 /*******************************************************************************
120 DECLARATION: FGColumnVector
121 *******************************************************************************/
122
123 class FGColumnVector : public FGMatrix
124 {
125 public:
126   FGColumnVector(void);
127   FGColumnVector(int m);
128   FGColumnVector(const FGColumnVector& b);
129   ~FGColumnVector();
130
131   FGColumnVector operator*(const double scalar);
132   FGColumnVector operator*(const FGColumnVector& V);   // Cross product operator
133   FGColumnVector operator/(const double scalar);
134   FGColumnVector operator+(const FGColumnVector& B);
135   FGColumnVector operator-(const FGColumnVector& B);
136   float Magnitude(void);
137   FGColumnVector Normalize(void);
138
139   friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
140   friend FGColumnVector operator*(const FGMatrix& M, const FGColumnVector& V);
141
142   double& operator()(int m) const;
143   
144   FGColumnVector multElementWise(const FGColumnVector& V);
145 };
146
147 /******************************************************************************/
148 #endif