I hope you can help me. For school I have to create a QT program to input a matrix (mArray) with complex numbers (mReal and mImag) and then get the result after the Gaussian Elimination (see CMatrix).
Actually its my first C++ program and first time I am using QT (Creator 4.0.0; QT 5.6.0). Its probably a silly mistake by me. But for now operators are my worst enemy and Im sitting on this problem for hours!
I created operator overloads in my CKomplex class to easily calculate with complex numbers. But it seems that the CMatrix class cant find them. Probably because of the wrong signature
One of my build errors is:
1
2
3
2
3
C:\Users\User\Documents\QTProjects\MatrixKomplex\cmatrix.cpp:97: Fehler: no match for 'operator==' (operand types are 'CKomplex' and 'double') if (mArray[newRow][row] == 1.) { ^
All other errors are the same just on different lines and with different operators
Spoiler
Arrows on the operator
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
C:\Users\User\Documents\QTProjects\MatrixKomplex\cmatrix.cpp:115: Fehler: no match for 'operator=' (operand types are 'CKomplex' and 'double') mArray[row][icol] = 1.; ^ C:\Users\User\Documents\QTProjects\MatrixKomplex\cmatrix.cpp:129: Fehler: no match for 'operator!' (operand type is 'CKomplex') if (!mArray[row][col]) return false; ^ C:\Users\User\Documents\QTProjects\MatrixKomplex\cmatrix.cpp:134: Fehler: no match for 'operator=' (operand types are 'CKomplex' and 'double') mArray[row][col] = 0.; ^ C:\Users\User\Documents\QTProjects\MatrixKomplex\cmatrix.cpp:136: Fehler: no match for 'operator-=' (operand types are 'CKomplex' and 'CKomplex') mArray[row][icol] -= mArray[col][icol] * factor; ^
Even though I declared them:
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
// CKomplex.h bool operator==(number &rhs); // number is a typedef of double // ..CKomplex.cpp bool CKomplex::operator==(number &rhs) { if (mReal == rhs) { if (!mImag) { return true; } } return false; }
It seems that operator /= and / and == (both CKomplex) do work. Atleast when the compiler didnt just randomly stop which I dont think so.
Ways I tried:
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
// inline with 2 parameters bool operator==(CKomplex &lhs, number &rhs) { return true; } // results in C:\Users\User\Documents\QTProjects\MatrixKomplex\ckomplex.h:67: Fehler: 'bool CKomplex::operator==(CKomplex&, number&)' must take exactly one argument bool operator==(CKomplex &lhs, number &rhs) { ^
1
2
3
4
2
3
4
// inline friend friend bool operator==(CKomplex &lhs, number &rhs) { 	return true; }
I cant find help in the internet too.
Note that CMatrix works with the double datatype flawless if you delete the Complex template in the last line of CMatrix.cpp
All classes
Complex numbers
Note that number is actually double (line 10)
CKomplex.h
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
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
#ifndef CKOMPLEX_H #define CKOMPLEX_H #include <math.h> #include <qmath.h> #include <qstring.h> #include <iostream> using namespace std; typedef double number; class CKomplex { private: // Realteil number mReal; // Imaginärteil number mImag; public: // Konstruktor CKomplex(number real = 0); CKomplex(number real, number imag); CKomplex(number radius, number phi, bool isRad); // Get & Setter number GetRadius(); void SetRadius(number radius); number GetPhi(bool isRad = true); void SetPhi(number phi, bool isRad = true); number GetReal() { return mReal; } void SetReal(number real) { mReal = real; } number GetImag() { return mImag; } void SetImag(number imag) { mImag = imag; } // Operator void operator+=(CKomplex &rhs); void operator-=(CKomplex &rhs); void operator*=(CKomplex &rhs); void operator/=(CKomplex &rhs); void operator=(CKomplex &rhs); void operator+=(number &rhs); void operator-=(number &rhs); void operator*=(number &rhs); void operator/=(number &rhs); void operator=(number &rhs); friend CKomplex operator+(CKomplex &lhs, CKomplex &rhs); friend CKomplex operator-(CKomplex &lhs, CKomplex &rhs); friend CKomplex operator*(CKomplex &lhs, CKomplex &rhs); friend CKomplex operator/(CKomplex &lhs, CKomplex &rhs); friend CKomplex operator+(CKomplex &lhs, number &rhs); friend CKomplex operator-(CKomplex &lhs, number &rhs); friend CKomplex operator*(CKomplex &lhs, number &rhs); friend CKomplex operator/(CKomplex &lhs, number &rhs); friend CKomplex operator+(number &lhs, CKomplex &rhs); friend CKomplex operator-(number &lhs, CKomplex &rhs); friend CKomplex operator*(number &lhs, CKomplex &rhs); friend CKomplex operator/(number &lhs, CKomplex &rhs); bool operator==(CKomplex &rhs); bool operator!=(CKomplex &rhs); bool operator> (CKomplex &rhs); bool operator< (CKomplex &rhs); bool operator>=(CKomplex &rhs); bool operator<=(CKomplex &rhs); bool operator==(number &rhs); bool operator!=(number &rhs); bool operator> (number &rhs); bool operator< (number &rhs); bool operator>=(number &rhs); bool operator<=(number &rhs); /* TO* TOSTRING METHODS */ // QString QStrEuler(); // QString QStrPolar(); // QString QStrKarte(); // void CoutEuler(); // void CoutPolar(); // void CoutKarte(); }; #endif // CKOMPLEX_H
CKomplex.cpp
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#include <QCoreApplication> #include <math.h> #include <stdio.h> #include <iostream> #include <iomanip> #include <stddef.h> #include <ckomplex.h> using namespace std; /* KONSTRUKTOR */ CKomplex::CKomplex(number real) { mReal = real; mImag = 0; } CKomplex::CKomplex(number real, number imag) { mReal = real; mImag = imag; } CKomplex::CKomplex(number radius, number phi, bool isRad) { SetRadius(radius); phi = (isRad ? phi : (phi*(M_PI/180))); SetPhi(phi); } /* GET SET METHODEN */ number CKomplex::GetRadius() { return sqrt(mReal*mReal + mImag * mImag); } void CKomplex::SetRadius(number radius){ number phi = GetPhi(); mReal = cos(phi) * radius; mImag = sin(phi) * radius; } number CKomplex::GetPhi(bool isRad) { number phiRad = atan(mImag / mReal); return (isRad ? phiRad : (number)(phiRad*(M_PI/180))); } void CKomplex::SetPhi(number phi, bool isRad) { number radius = GetRadius(); phi = (isRad ? phi : (phi*(M_PI/180))); mReal = cos(phi) * radius; mImag = sin(phi) * radius; } /* OPERATIONSÜBERLADUNGEN */ void CKomplex::operator+=(CKomplex &rhs) { this->mReal += rhs.GetReal(); this->mImag += rhs.GetImag(); } void CKomplex::operator-=(CKomplex &rhs) { mReal -= rhs.GetReal(); mImag -= rhs.GetImag(); } void CKomplex::operator*=(CKomplex &rhs) { mReal = (mReal * rhs.GetReal()) - (mImag * rhs.GetImag()); mImag = mImag - rhs.GetImag(); } void CKomplex::operator/=(CKomplex &rhs) { mReal = ((mReal*rhs.GetReal()) + (mImag * rhs.GetImag())) / ((mImag*mImag) + (rhs.GetImag() * rhs.GetImag())); mImag = ((mImag*rhs.GetReal())- mReal*rhs.GetImag()) / ((mReal*mReal) + (rhs.GetImag()*rhs.GetImag())); } void CKomplex::operator=(CKomplex &rhs) { mReal = rhs.GetReal(); mImag = rhs.GetImag(); } void CKomplex::operator+=(number &rhs) { mReal += rhs; } void CKomplex::operator-=(number &rhs) { mReal -= rhs; } void CKomplex::operator*=(number &rhs) { mReal = mReal * rhs; } void CKomplex::operator/=(number &rhs) { mReal = (mReal*rhs) / (mImag*mImag); mImag = (mImag*rhs) / (mReal*mReal); } void CKomplex::operator=(number &rhs) { mReal = rhs; mImag = 0; } CKomplex operator+(CKomplex &lhs, CKomplex &rhs) { number real = lhs.GetReal() + rhs.GetReal(); number imag = lhs.GetImag() + rhs.GetImag(); return CKomplex(real, imag); } CKomplex operator-(CKomplex &lhs, CKomplex &rhs) { number real = lhs.GetReal() - rhs.GetReal(); number imag = lhs.GetImag() - rhs.GetImag(); return CKomplex(real, imag); } CKomplex operator*(CKomplex &lhs, CKomplex &rhs) { number real = (lhs.GetReal() * rhs.GetReal()) - (lhs.GetImag() * rhs.GetImag()); number imag = lhs.GetImag() - rhs.GetImag(); return CKomplex(real, imag); } CKomplex operator/(CKomplex &lhs, CKomplex &rhs) { number real =((lhs.GetReal() * rhs.GetReal()) + (lhs.GetImag() * rhs.GetImag())) / ((lhs.GetImag()* lhs.GetImag()) + (rhs.GetImag() * rhs.GetImag())); number imag =((lhs.GetImag()*rhs.GetReal())- lhs.GetReal()*rhs.GetImag()) / ((lhs.GetReal()* lhs.GetReal()) + (rhs.GetImag()*rhs.GetImag())); return CKomplex(real, imag); } CKomplex operator+(CKomplex &lhs, number &rhs) { number real = lhs.GetReal() + rhs; number imag = lhs.GetImag(); return CKomplex(real, imag); } CKomplex operator-(CKomplex &lhs, number &rhs) { number real = lhs.GetReal() - rhs; number imag = lhs.GetImag(); return CKomplex(real, imag); } CKomplex operator*(CKomplex &lhs, number &rhs) { number real = lhs.GetReal() * rhs; number imag = lhs.GetImag(); return CKomplex(real, imag); } CKomplex operator/(CKomplex &lhs, number &rhs) { number real =(lhs.GetReal() * rhs) / ((lhs.GetImag()* lhs.GetImag())); number imag =(lhs.GetImag()*rhs) / (lhs.GetReal()* lhs.GetReal()); return CKomplex(real, imag); } CKomplex operator+(number &lhs, CKomplex &rhs) { number real = lhs + rhs.GetReal(); number imag = rhs.GetImag(); return CKomplex(real, imag); } CKomplex operator-(number &lhs, CKomplex &rhs) { number real = lhs - rhs.GetReal(); number imag = rhs.GetImag(); return CKomplex(real, imag); } CKomplex operator*(number &lhs, CKomplex &rhs) { number real = lhs * rhs.GetReal(); number imag = rhs.GetImag(); return CKomplex(real, imag); } CKomplex operator/(number &lhs, CKomplex &rhs) { number real =(lhs * rhs.GetReal()) / (rhs.GetImag() * rhs.GetImag()); number imag =(lhs*rhs.GetImag()) / ((lhs* lhs) + (rhs.GetImag()*rhs.GetImag())); return CKomplex(real, imag); } bool CKomplex::operator==(CKomplex &rhs) { if (mReal == rhs.GetReal()) { if (mImag == rhs.GetImag()) { return true; } } return false; } bool CKomplex::operator!=(CKomplex &rhs) { if (mReal == rhs.GetReal()) { if (mImag == rhs.GetImag()) { return false; } } return true; } bool CKomplex::operator> (CKomplex &rhs) { if (GetRadius() > rhs.GetRadius()) { return true; } return false; } bool CKomplex::operator>=(CKomplex &rhs) { if (GetRadius() >= rhs.GetRadius()) { return true; } return false; } bool CKomplex::operator< (CKomplex &rhs) { if (GetRadius() < rhs.GetRadius()) { return true; } return false; } bool CKomplex::operator<=(CKomplex &rhs) { if (GetRadius() <= rhs.GetRadius()) { return true; } return false; } bool CKomplex::operator==(number &rhs) { if (mReal == rhs) { if (!mImag) { return true; } } return false; } bool CKomplex::operator!=(number &rhs) { if (mReal == rhs) { if (!mImag) { return false; } } return true; } bool CKomplex::operator> (number &rhs) { if (GetRadius() > rhs) { return true; } return false; } bool CKomplex::operator< (number &rhs) { if (GetRadius() < rhs) { return true; } return false; } bool CKomplex::operator>=(number &rhs) { if (GetRadius() >= rhs) { return true; } return false; } bool CKomplex::operator<=(number &rhs) { if (GetRadius() <= rhs) { return true; } return false; } /* OUTPUT METHODEN COUT STRING CHAR */ // QString CKomplex::QStrEuler() { // QString temp = QString(); // temp += QString("Z = %1e^(%2j)") // .arg(GetRadius()) // .arg(GetPhi()); // temp.end(); // return temp; //} // QString CKomplex::QStrPolar() { // QString temp = QString(); // // Todo // return temp; //} // QString CKomplex::QStrKarte() { // QString temp = QString("Z = %1") // .arg(mReal); // if (mImag > 0) // temp += QString(" +j%2") // .arg(mImag); // else { // if (mImag < 0) { // temp += QString("-j%2") // .arg(mImag*(-1)); // } else { // mImag == 0 // // Z = real + j*0 = real // } // } // return temp; //} // void CKomplex::CoutEuler() { // cout << "Z = " << GetRadius() << "*e^(j*" << GetPhi() << ")" << endl; //} // void CKomplex::CoutKarte() { // cout << "Z = " << mReal; // if (mImag > 0) // cout << "+j " << mImag; // else { // if (mImag < 0) { // cout << "-j " << abs(mImag); // } else { // mImag == 0 // // real + j*0 = real // } // } // cout << endl; //} // void CKomplex::CoutPolar() { // //cout << "|Z| = "; // TODO ? //}
Matrix with GJA
Note that T (template) is supposed to be CKomplex, but can also be double.
CMatrix.h
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
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
#ifndef CMATRIX_H #define CMATRIX_H #include <QCoreApplication> #include <ckomplex.h> #include <cmatrix.h> #include <stdio.h> #include <iostream> #include <stddef.h> #include <math.h> using namespace std; template <typename T> class CMatrix { /* Place indicies like this: col1 col2 col3 11 12 13 -- row 1 21 22 23 -- row 2 31 32 33 -- row 3 */ public: // Konstruktor // Standard CMatrix(unsigned rows, unsigned cols); CMatrix(unsigned rows, unsigned cols, T ** mArray); CMatrix(int rows, int cols); CMatrix(int rows, int cols, T ** mArray); // Kopier CMatrix(CMatrix& matrix); // Dekonstruktor ~CMatrix(); // Aufrufmethoden T ** GetMatrix(); CMatrix GetCMatrix() { return *this; } int GetRowMax(); int GetColMax(); void SetValue(unsigned row, unsigned col, T value); T GetValue(unsigned row, unsigned col); // Interaktionsmethoden bool Create1(unsigned row); bool Create0(unsigned row, unsigned col); void GJA(); // Arithmetik und Logik void Swap(unsigned row1, unsigned row2); // Dreieckstausch // Operationsüberladungsmethoden //CMatrix operator[][](unsigned row, unsigned col); // TODO // Ausgabe- und Debugmethoden QString QStrTable(); QString QStrCopy(); void CoutTable(); void CoutCopy(); private: T** mArray; unsigned mRowMax; // Das letze Element +1 ( => 0 < row < mRowMax) unsigned mColMax; // 0 < col < mColMax void InitArray(); }; #endif // CMATRIX_H
CMatrix.cpp
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include "cmatrix.h" #include "ckomplex.h" #include <QCoreApplication> #include <math.h> #include <stdio.h> #include <iostream> #include <iomanip> #include <stddef.h> using namespace std; /* KONSTRUKTOR DEKONSTRUKTOR */ template <class T> CMatrix<T>::CMatrix(unsigned rows, unsigned cols) { mRowMax = rows; mColMax = cols; InitArray(); } template <class T> CMatrix<T>::CMatrix(unsigned rows, unsigned cols, T **mArray) { mRowMax = rows; mColMax = cols; InitArray(); this->mArray = mArray; } template <class T> CMatrix<T>::CMatrix(int rows, int cols) { if (rows > 0 && cols > 0) { mRowMax = rows; mColMax = cols; InitArray(); } } template <class T> CMatrix<T>::CMatrix(int rows, int cols, T **mArray) { if (rows > 0 && cols > 0) { mRowMax = rows; mColMax = cols; InitArray(); this->mArray = mArray; } } template <class T> CMatrix<T>::CMatrix(CMatrix& matrix) { this->mRowMax = matrix.mRowMax; this->mColMax = matrix.mColMax; InitArray(); this->mArray = matrix.mArray; } template <class T> CMatrix<T>::~CMatrix() { for(unsigned i = 0; i < mColMax; i++) { delete[] mArray[i]; } delete[] mArray; } template <class T> void CMatrix<T>::InitArray() // PRIVATE (Nur bei Konstruktor verwenden) { mArray = new T*[mRowMax]; for(unsigned irow = 0; irow < mRowMax; irow++) { mArray[irow] = new T[mColMax]; } } /* GET & SET METHODEN */ template <class T> T ** CMatrix<T>::GetMatrix() { return mArray; } template <class T> int CMatrix<T>::GetRowMax() { return mRowMax; } template <class T> int CMatrix<T>::GetColMax() { return mColMax; } template <class T> void CMatrix<T>::SetValue(unsigned row, unsigned col, T value){ mArray[row][col] = value; } template <class T> T CMatrix<T>::GetValue(unsigned row, unsigned col) { return mArray[row][col]; } /* Interaktions Methoden */ // Eins 1 in matrix[row][row] erzeugen durch Tauschen oder Kalkulation template <class T> bool CMatrix<T>::Create1(unsigned row) { // Tausch Finden for (unsigned newRow = 0; newRow < mRowMax; newRow++) { if (mArray[newRow][row] == 1.) { cout << " Create1 infos: row=" << row+1 << "/ newrow=" << newRow+1 << endl; // DEBUG PURPOSE Swap(row, newRow); return true; } } // Berechne Reihe T teilerWert; if (row < mColMax) { teilerWert = mArray[row][row]; // if (teilerWert == 1.0) return true; } else { return false; } for (unsigned icol = 0; icol < mColMax; icol++) { if (row == icol) { mArray[row][icol] = 1.; } else { mArray[row][icol] /= teilerWert; } } //cout << " Create1 infos: row=" << row+1 << "/ factor=" << teilerWert << endl; // DEBUG PURPOSE return true; } // Eine 0 in matrix[row][col] erzeugen indem man nach geeigneten row2 sucht template <class T> bool CMatrix<T>::Create0(unsigned row, unsigned col) { // Wenn Eingabe falsch if (row > mColMax) return false; if (!mArray[row][col]) return false; T factor = mArray[row][col] / mArray[col][col]; for (unsigned icol = 0; icol < mColMax; icol++) { if (icol == col) { mArray[row][col] = 0.; } else { mArray[row][icol] -= mArray[col][icol] * factor; } } //cout << " Create0 infos: row=" << row+1 << "| col=" << col+1 << "| factor=" << factor << endl; // DEBUG PURPOSE return true; } template <class T> void CMatrix<T>::GJA() { for (unsigned col= 0; col < mColMax-1; col++) { // -1 um den ERGEBNISVEKTOR auszulassen! Create1(col); for (unsigned row= 0; row < mRowMax; row++) { if (row != col) { Create0(row,col); } } } } /* Tabellenkalkulation Arithmetik und Logik */ template <class T> void CMatrix<T>::Swap(unsigned row1, unsigned row2) { // Dreieckstausch T * temp = new T[mColMax]; temp = mArray[row1]; mArray[row1] = mArray[row2]; mArray[row2] = temp; } /* OPERATOR ÜBERLADUNG */ //CMatrix CMatrix<T>::operator[][](unsigned row, unsigned col) { // CMatrix temp = this->GetCMatrix(); //} /* Ausgabe & Debug */ // Ausgabe um das Array zu kopieren template <class T> void CMatrix<T>::CoutCopy() { for (unsigned row = 0; row < mRowMax; row++) { for (unsigned col = 0; col < mColMax; col++) { //cout << "matrix->SetEntry(" << row << "," << col << ", " << mArray[row][col] << " );" << endl; } } } // Übersichtliche Ausgabe //template <class T> void CMatrix<T>::CoutTable() { // cout << "> Matrix Table" << endl; // for (unsigned row=0; row < mRowMax; row++) { // cout << setw(10); // for (unsigned col=0; col < mColMax; col++) { // //cout << setw(3) << " x" << row+1 << col+1 << "= " << mArray[row][col] << ";"; // } // cout << endl; // } // cout << endl; //} //template <class T> QString CMatrix<T>::QStrTable() { // QString temp = QString("> Matrix Table"); // for (unsigned row=0; row < mRowMax; row++) { // for (unsigned col=0; col < mColMax; col++) { // T zahlAktuell = mArray[row][col]; // temp += QString("x%1%2: %3;") // .arg(row+1) // .arg(col+1) // .arg(zahlAktuell); // } // } // temp.end(); // return temp; //} //template <class T> QString CMatrix<T>::QStrCopy() { // QString temp = QString(); // for (unsigned row=0; row < mRowMax; row++) { // for (unsigned col=0; col < mColMax; col++) { // CKomplex<T> zahlAktuell = mArray[row][col]; // temp += QString("matrix->SetEntry(%1 , %2 , %3);") // .arg(row+1) // .arg(col+1) // .arg(zahlAktuell.QStrEuler()); // } // } // temp.end(); // return temp; //} // Template Definition template class CMatrix<double>; template class CMatrix<CKomplex>;
edited 1×, last 23.12.16 07:53:26 pm