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