-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmatrix_exponential_prb.cpp
212 lines (176 loc) · 4.56 KB
/
matrix_exponential_prb.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# include <cstdlib>
# include <iostream>
# include <cmath>
# include <complex>
using namespace std;
# include "matrix_exponential.hpp"
# include "test_matrix_exponential.hpp"
# include "c8lib.hpp"
# include "r8lib.hpp"
int main ( );
void matrix_exponential_test01 ( );
void matrix_exponential_test02 ( );
//****************************************************************************80
int main ( )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for MATRIX_EXPONENTIAL_PRB.
//
// Discussion:
//
// MATRIX_EXPONENTIAL_PRB tests the MATRIX_EXPONENTIAL library.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 05 March 2013
//
// Author:
//
// John Burkardt
//
{
timestamp ( );
cout << "\n";
cout << "MATRIX_EXPONENTIAL_TEST:\n";
cout << " C++ version\n";
cout << " Test the MATRIX_EXPONENTIAL library.\n";
cout << " The C8LIB and R8LIB libraries are needed.\n";
cout << " This test needs the TEST_MATRIX_EXPONENTIAL library.\n";
matrix_exponential_test01 ( );
matrix_exponential_test02 ( );
//
// Terminate.
//
cout << "\n";
cout << "MATRIX_EXPONENTIAL_TEST:\n";
cout << " Normal end of execution.\n";
cout << "\n";
timestamp ( );
return 0;
}
//****************************************************************************80
void matrix_exponential_test01 ( )
//****************************************************************************80
//
// Purpose:
//
// MATRIX_EXPONENTIAL_TEST01 compares real matrix exponential algorithms.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 02 December 2011
//
// Author:
//
// John Burkardt
//
{
double *a;
double *a_exp;
int n;
int test;
int test_num;
cout << "\n";
cout << "MATRIX_EXPONENTIAL_TEST01:\n";
cout << " EXPM is MATLAB's matrix exponential function\n";
cout << " R8MAT_EXPM1 is an equivalent to EXPM\n";
cout << " R8MAT_EXPM2 uses a Taylor series approach\n";
cout << " R8MAT_EXPM3 relies on an eigenvalue calculation.\n";
test_num = r8mat_exp_test_num ( );
for ( test = 1; test <= test_num; test++ )
{
cout << "\n";
cout << " Test #" << test << "\n";
r8mat_exp_story ( test );
n = r8mat_exp_n ( test );
cout << " Matrix order N = " << n << "\n";
a = r8mat_exp_a ( test, n );
r8mat_print ( n, n, a, " Matrix:" );
a_exp = r8mat_expm1 ( n, a );
r8mat_print ( n, n, a_exp, " R8MAT_EXPM1(A):" );
delete [] a_exp;
a_exp = r8mat_expm2 ( n, a );
r8mat_print ( n, n, a_exp, " R8MAT_EXPM2(A):" );
delete [] a_exp;
//
// a_exp = r8mat_expm3 ( n, a );
// r8mat_print ( n, n, a_exp, " R8MAT_EXPM3(A):" );
// delete [] a_exp;
//
a_exp = r8mat_exp_expa ( test, n );
r8mat_print ( n, n, a_exp, " Exact Exponential:" );
delete [] a_exp;
delete [] a;
}
return;
}
//****************************************************************************80
void matrix_exponential_test02 ( )
//****************************************************************************80
//
// Purpose:
//
// MATRIX_EXPONENTIAL_TEST02 compares complex matrix exponential algorithms.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 05 March 2013
//
// Author:
//
// John Burkardt
//
{
complex <double> *a;
complex <double> *a_exp;
int n;
int test;
int test_num;
cout << "\n";
cout << "MATRIX_EXPONENTIAL_TEST02:\n";
cout << " EXPM is MATLAB's matrix exponential function\n";
cout << " C8MAT_EXPM1 is an equivalent to EXPM\n";
cout << " C8MAT_EXPM2 uses a Taylor series approach\n";
cout << " C8MAT_EXPM3 relies on an eigenvalue calculation.\n";
test_num = c8mat_exp_test_num ( );
for ( test = 1; test <= test_num; test++ )
{
cout << "\n";
cout << " Test #" << test << "\n";
c8mat_exp_story ( test );
n = c8mat_exp_n ( test );
cout << " Matrix order N = " << n << "\n";
a = c8mat_exp_a ( test, n );
c8mat_print ( n, n, a, " Matrix:" );
a_exp = c8mat_expm1 ( n, a );
c8mat_print ( n, n, a_exp, " C8MAT_EXPM1(A):" );
delete [] a_exp;
// a_exp = c8mat_expm2 ( n, a );
// c8mat_print ( n, n, a_exp, " C8MAT_EXPM2(A):" );
// delete [] a_exp;
//
// a_exp = c8mat_expm3 ( n, a );
// c8mat_print ( n, n, a_exp, " C8MAT_EXPM3(A):" );
// delete [] a_exp;
//
a_exp = c8mat_exp_expa ( test, n );
c8mat_print ( n, n, a_exp, " Exact Exponential:" );
delete [] a_exp;
delete [] a;
}
return;
}