-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray2matrix.cpp
executable file
·61 lines (54 loc) · 1.6 KB
/
Array2matrix.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
/////////////////////////////////////////////////////////////////////////
// Program : array2matrix.cpp
// Coded by : Prof. Gang-Gyoo Jin, Korea Maritime University
// Coded on : 12/12/2003
#include "cmatrix.h"
/////////////////////////////////////////////////////////////////////////
// Converts a REAL array to a REAL vector
void Array2Vector(REAL a[], RVECTOR &b)
{
for(int i=0; i<b.num; i++)
b(i)= *a++;
}
/////////////////////////////////////////////////////////////////////////
// Converts a REAL array to a COMPLEX vector
void Array2Vector(REAL a[], CVECTOR &b)
{
for(int i=0; i<b.num; i++)
{
b(i).Re= *a++;
b(i).Im= *a++;
}
}
/////////////////////////////////////////////////////////////////////////
// Converts a REAL array to a REAL matrix
void Array2Matrix(REAL **a, RMATRIX &b)
{
for(int i=0; i<b.n; i++)
for(int j=0; j<b.m; j++)
b(i,j)= a[i][j];
}
/////////////////////////////////////////////////////////////////////////
// Converts a REAL vector to a REAL array
void Vector2Array(const RVECTOR &a, REAL b[])
{
for(int i=0; i<a.num; i++) *b++= a(i);
}
/////////////////////////////////////////////////////////////////////////
// Converts a COMPLEX vector to a REAL array
void Vector2Array(const CVECTOR &a, REAL b[])
{
for(int i=0; i<a.num; i++)
{
*b++= a(i).Re;
*b++= a(i).Im;
}
}
/////////////////////////////////////////////////////////////////////////
// Converts a REAL matrix to a REAL array
void Matrix2Array(const RMATRIX &a, REAL **b)
{
for(int i=0; i<a.n; i++)
for(int j=0; j<a.m; j++)
b[i][j]= a(i,j);
}