-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtrx.cpp
128 lines (116 loc) · 2.19 KB
/
mtrx.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
#include <iostream>
#include <conio.h>
#include <string>
#include <sstream>
#include <math.h>
#include "mtrx.h"
using namespace std;
#define MAXSIZE 21 /* Maximum der Matrix */
#define AZERO 1.0e-30
matrix::matrix(int zeilen, int spalten)
{
int i,j;
dim_y=zeilen;
dim_x=spalten;
elem=new Complex*[dim_x];
for (i=0;i<dim_y;i++)
elem[i]=new Complex[dim_y];
for(i=0; i<dim_y; i++)
{
for(j=0; j<dim_x; j++)
elem[i][j].Clear();
}
}
matrix::matrix(const matrix &quelle)
{
int i,j;
dim_y=quelle.dim_y;
dim_x=quelle.dim_x;
elem=new Complex*[dim_x];
for (i=0;i<dim_y;i++)
elem[i]=new Complex[dim_y];
for(i=0; i<dim_y; i++)
{
for(j=0; j<dim_x; j++)
elem[i][j]=quelle.elem[i][j];
}
}
/*matrix::~matrix()
{
if(dim_y>=dim_x)
{
for (int i=0;i<dim_y;i++)
delete elem[i];
}
else
{
}
}*/
void matrix::StoreMatrix(string temp, int z, int s)
{
this->elem[z-1][s-1].StrToComp(temp);
}
Complex matrix::GetComp(int i, int j)
{
return(this->elem[i][j]);
}
void matrix::SetComp(int z, int s, Complex C)
{
this->elem[z-1][s-1].StoreComp(C);
}
matrix matrix::operator *(matrix m2)
{
matrix m_mul(this->dim_y,m2.dim_x);
Complex test;
test.SetRe(2);
test.SetIm(9);
for(int i=0; i<m_mul.dim_y; i++)
{
for(int j=0; j<m_mul.dim_x; j++) {
for(int k=0; k<this->dim_x; k++)
{
m_mul.elem[i][j]=this->elem[i][k]*m2.elem[k][j]+m_mul.elem[i][j];
}
//cout << endl << "M_mul(" << i << "," << j << "): " << m_mul.GetComp(i,j);
}
}
return(m_mul);
}
/*
void gauss(double a[MAXSIZE][MAXSIZE], int n, double b[MAXSIZE],
int& flag, double x[MAXSIZE])
{
double pivot,mult,temp;
int i,j,k;
flag=1; // flag = 1 -> Ergebnis gefunden
// Eliminations-phase
for (k=1;k<=n-1;k++)
{
pivot=a[k][k];
if ( fabs(pivot) < AZERO )
{
flag=0; // flag = 0 -> das Pivotelement ist 0
break;
}
for (i=k+1;i<=n;i++)
{
mult=a[i][k]/pivot ;
for (j=k+1;j<=n;j++)
a[i][j]=a[i][j]-a[k][j]*mult;
b[i]=b[i]-b[k]*mult;
}
}
// Zurück-substitution
flag=(flag) && (fabs(a[n][n] > AZERO));
if (flag)
{
x[n]=b[n]/a[n][n];
for (k=n-1;k>=1;k--)
{
temp=b[k];
for(j=k+1;j<=n;j++)
temp=temp-a[k][j]*x[j];
x[k]=temp/a[k][k];
}
}
}*/