-
Notifications
You must be signed in to change notification settings - Fork 0
/
Matrix.cpp
92 lines (84 loc) · 1.88 KB
/
Matrix.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
// Matrix.cpp: implementation of the Matrix class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Matrix.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
int Matrix::MtxMultiply(double *pMtxA, double *pMtxB, int m, int n, int q, double *pMtxC) {
double MtxA[3][3];
double MtxB[3][3];
double MtxC[3][3];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
MtxA[i][j] = *pMtxA++;
}
}
for (i = 0; i < n; i++) {
for (int j = 0; j < q; j++) {
MtxB[i][j] = *pMtxB++;
}
}
for (i = 0; i < m; i++) {
for (int j = 0; j < q; j++) {
MtxC[i][j] = 0;
for (int k = 0; k < n; k++)
MtxC[i][j] += MtxA[i][k] * MtxB[k][j];
}
}
for (i = 0; i < m; i++) {
for (int j = 0; j < q; j++) {
*pMtxC++ = MtxC[i][j];
}
}
// pMtxC=MtxC[0];
/* int p;
double ti;
double si;
div_t div_result;
div_result=div(n,2);
p=div_result.quot;
for(int i=0;i<m;i++)
{
for(int j=0;j<p;j++)
{
ti=MtxA[i][2*j]*MtxA[i][2*j+1];
}
}
for(i=0;i<q;i++)
{
for(int j=0;j<p;j++)
{
si=MtxB[2*j][i]*MtxB[2*j+1][i];
}
}
*/
return 0;
}
int Matrix::MtxParaMultiply(double *pMtxA, double MPParam, int m, int n, double *pMtxB) {
for (int i = 0; i < m * n; i++) {
*pMtxB = *pMtxA * MPParam;
pMtxA++;
pMtxB++;
}
return 0;
}
int Matrix::MtxSubtract(double *pMtxA, double *pMtxB, int m, int n, double *pMtxC) {
for (int i = 0; i < m * n; i++) {
*pMtxC = *pMtxA - *pMtxB;
pMtxA++;
pMtxB++;
pMtxC++;
}
return 0;
}
int Matrix::MtxPlus(double *pMtxA, double *pMtxB, int m, int n, double *pMtxC) {
for (int i = 0; i < m * n; i++) {
*pMtxC = *pMtxA + *pMtxB;
pMtxA++;
pMtxB++;
pMtxC++;
}
return 0;
}