]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGMatrix.h
Synced with latest JSBSim as of June 5, 2001.
[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 <math.h>
26 #  include <simgear/compiler.h>
27 #  include STL_STRING
28 #  include STL_FSTREAM
29 #  include STL_IOSTREAM
30    SG_USING_STD(string);
31    SG_USING_STD(ostream);
32    SG_USING_STD(istream);
33    SG_USING_STD(cerr);
34    SG_USING_STD(cout);
35    SG_USING_STD(endl);
36 #else
37 #  include <fstream>
38 #  include <cmath>
39 #  include <iostream>
40 #  include <string>
41    using std::string;
42    using std::ostream;
43    using std::istream;
44    using std::cerr;
45    using std::cout;
46    using std::endl;
47 #endif
48
49
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 DEFINITIONS
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54 #define ID_MATRIX "$Id$"
55
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 FORWARD DECLARATIONS
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59
60 class FGColumnVector;
61
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 DECLARATION: MatrixException
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65
66 class MatrixException /* :  public exception */
67 {
68 public:
69   string Message;
70 };
71
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 DECLARATION: FGMatrix
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
75
76 class FGMatrix
77 {
78 public:
79   FGMatrix(unsigned int r, unsigned int c);
80   FGMatrix(const FGMatrix& A);
81   FGMatrix(void) {};
82   ~FGMatrix(void);
83
84   FGMatrix& operator=(const FGMatrix& A);
85   inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
86
87   FGColumnVector operator*(const FGColumnVector& Col);
88
89   unsigned int Rows(void) const;
90   unsigned int Cols(void) const;
91
92   void T(void);
93   void InitMatrix(void);
94   void InitMatrix(double value);
95
96   FGMatrix operator-(const FGMatrix& B);
97   FGMatrix operator+(const FGMatrix& B);
98   FGMatrix operator*(const FGMatrix& B);
99   FGMatrix operator/(const double scalar);
100   FGMatrix& operator<<(const float ff);
101
102   friend ostream& operator<<(ostream& os, const FGMatrix& M);
103   friend istream& operator>>(istream& is, FGMatrix& M);
104
105   void operator-=(const FGMatrix &B);
106   void operator+=(const FGMatrix &B);
107   void operator*=(const FGMatrix &B);
108   void operator*=(const double scalar);
109   void operator/=(const double scalar);
110
111   friend FGMatrix operator*(double scalar,FGMatrix& A);
112
113   void SetOParams(char delim,int width,int prec, int origin=0);
114
115 protected:
116   double **data;
117   unsigned int rows,cols;
118
119 private:
120   char delim;
121   int width,prec,origin;
122   void TransposeSquare(void);
123   void TransposeNonSquare(void);
124   unsigned int rowCtr, colCtr;
125   void Debug(void);
126 };
127
128 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 DECLARATION: FGColumnVector
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
131
132 class FGColumnVector : public FGMatrix
133 {
134 public:
135   FGColumnVector(void);
136   FGColumnVector(int m);
137   FGColumnVector(const FGColumnVector& b);
138   ~FGColumnVector(void);
139
140   FGColumnVector operator*(const double scalar);
141   FGColumnVector operator*(const FGColumnVector& V);   // Cross product operator
142   FGColumnVector operator/(const double scalar);
143   FGColumnVector operator+(const FGColumnVector& B); // must not return reference
144   FGColumnVector operator-(const FGColumnVector& B);
145   float Magnitude(void);
146   FGColumnVector Normalize(void);
147
148   friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
149   friend FGColumnVector operator*(const FGMatrix& M, const FGColumnVector& V);
150
151   double& operator()(int m) const;
152
153   FGColumnVector multElementWise(const FGColumnVector& V);
154
155 private:
156   void Debug(void);
157 };
158
159 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160 #endif