-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatLinalg.h
More file actions
44 lines (38 loc) · 755 Bytes
/
matLinalg.h
File metadata and controls
44 lines (38 loc) · 755 Bytes
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
#ifndef _MATRIX_
#include "Mat.h"
#define _MATRIX_
#endif
Matrix vstack(Matrix a,Matrix b){
int rowa=a.row(),cola=a.col(),rowb=b.row(),colb=b.col();
if(cola!=colb) return Matrix();
Matrix newMat(rowa+rowb,cola);
int i,j;
for(i=1;i<=rowa;++i){
for(j=1;j<=cola;++j){
newMat(i,j)=a(i,j);
}
}
for(i=1;i<=rowb;++i){
for(j=1;j<=cola;++j){
newMat(i+rowa,j)=b(i,j);
}
}
return newMat;
}
Matrix hstack(Matrix a,Matrix b){
int rowa=a.row(),cola=a.col(),rowb=b.row(),colb=b.col();
if(rowa!=rowb) return Matrix();
Matrix newMat(rowa,cola+colb);
int i,j;
for(i=1;i<=rowa;++i){
for(j=1;j<=cola;++j){
newMat(i,j)=a(i,j);
}
}
for(i=1;i<=rowa;++i){
for(j=1;j<=colb;++j){
newMat(i,j+cola)=b(i,j);
}
}
return newMat;
}