File: matrix.h

package info (click to toggle)
flying 6.20-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 752 kB
  • ctags: 1,873
  • sloc: cpp: 10,966; makefile: 189
file content (130 lines) | stat: -rw-r--r-- 2,823 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef _matrix_h
#define _matrix_h

#ifndef _vector_h
#	include "vector.h"
#endif

//
// -------------------------------------------------------------------------
// class Matrix : Matrixklasse als Liste gleichdimensionierter Vektoren
// -------------------------------------------------------------------------
//


class Matrix {
	protected:
		short		dim;
		Vector	*data;

	public:
		Matrix()									{ dim=0; }
		Matrix( int n, int m, ... );
		Matrix( const Matrix &m );
		~Matrix()								{ if (dim)	delete [] data; }

		void show(const char *str=0) const;

		int Rows() const						{ return dim; }
		int Cols() const;

	protected:
		void Resize(int i);
		void Resize(int i, int j);
		Vector &GetRef(int i);
	public:
		const Vector &operator()(int i) const
				{ return (i>=0&&i<dim)?data[i]:VectorZero; }
		Vector &operator[](int i)
				{ return (i>=0&&i<dim)?data[i]:GetRef(i); }

		int	IsZero() const;


	const Matrix& operator=(const Matrix &v);		// Copy
	const Matrix& operator<<=(Matrix &v);			// Move

	Matrix Matrix::operator+(const Matrix&) const;
	Matrix Matrix::operator-(const Matrix&) const;

	Matrix Matrix::operator*(const Real&) const;
	friend Matrix operator*(const Real&, const Matrix&);
	Matrix Matrix::operator/(const Real&) const;

	friend int operator==(const Matrix&, const Matrix&);
	friend int operator!=(const Matrix&, const Matrix&);
	const Matrix& operator+=(const Matrix&);
	const Matrix& operator-=(const Matrix&);
	const Matrix& operator*=(const Real&);
	const Matrix& operator/=(const Real&);
	Matrix Matrix::operator+() const;
	Matrix Matrix::operator-() const;

	friend Vector operator*(const Vector&, const Matrix&);
	friend Vector operator*(const Matrix&, const Vector&);
	const Matrix &operator*=(const Matrix&);
	friend Matrix operator*(const Matrix&, const Matrix&);

	friend Vector operator/(const Vector &b, const Matrix &a);
	friend int system_calc(Matrix &a, Vector *x, Vector &b);
};

inline Matrix Matrix::operator+() const
{
	return *this;
}
inline Matrix Matrix::operator-() const
{
Matrix	v(*this);
	return v*=Real(-1.0);
}


// Definitions of non-member binary operator functions

inline Matrix Matrix::operator+(const Matrix& z2) const
{
	if (dim>z2.dim) {
		Matrix	v(*this);
					return v+=z2;
	}
	else {
		Matrix	v(z2);
					return v+=*this;
	}
}
inline Matrix Matrix::operator-(const Matrix& z2) const
{
Matrix	v(*this);
			return v-=z2;
}

inline Matrix Matrix::operator*(const Real& r) const
{
Matrix	erg(*this);
			erg *= r;
			return erg;
}

inline Matrix Matrix::operator/(const Real& r) const
{
Matrix	erg(*this);
			erg /= r;
			return erg;
}


inline Matrix operator*(const Real& val, const Matrix& z2)
{
		return z2*val;		// kommutativ
}

inline int operator!=(const Matrix& z1, const Matrix& z2)
{
		return !(z1==z2);
}


extern Matrix MatrixZero;

#endif