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