-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatPlus.h
56 lines (55 loc) · 1.02 KB
/
matPlus.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
//加法
Matrix operator+(Matrix matb){
Matrix mata=*this;
int rowa=mata.row(),rowb=matb.row(),cola=mata.col(),colb=matb.col();
if( (rowa!=rowb)||(cola!=colb))
{
return NULL;
}
Matrix newMat(rowa,cola);
int i,j;
for(i=1;i<=rowa;++i)
for(j=1;j<=cola;++j)
{
newMat(i,j)=mata(i,j)+matb(i,j);
}
return newMat;
}
Matrix operator+=(Matrix matb){
Matrix mata=*this;
int rowa=mata.row(),rowb=matb.row(),cola=mata.col(),colb=matb.col();
if( (rowa!=rowb)||(cola!=colb))
{
return NULL;
}
int i,j;
for(i=1;i<=rowa;++i)
for(j=1;j<=cola;++j)
{
mata(i,j)+=matb(i,j);
}
return mata;
}
Matrix operator+(double C){
Matrix mat=*this;
int row=mat.row(),col=mat.col();
Matrix newMat(row,col);
int i,j;
for(i=1;i<=row;++i)
for(j=1;j<=col;++j)
{
newMat(i,j)=mat(i,j)+C;
}
return newMat;
}
Matrix operator+=(double C){
Matrix mat=*this;
int row=mat.row(),col=mat.col();
int i,j;
for(i=1;i<=row;++i)
for(j=1;j<=col;++j)
{
mat(i,j)+=C;
}
return mat;
}