[43ce9a]: src / slsb16cd.cc  Maximize  Restore  History

Download this file

239 lines (192 with data), 6.6 kB

  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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
Copyright (C) 2011 Lukas F. Reichlin
This file is part of LTI Syncope.
LTI Syncope is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LTI Syncope is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>.
TODO
Uses SLICOT SB16CD by courtesy of NICONET e.V.
<http://www.slicot.org>
Author: Lukas Reichlin <lukas.reichlin@gmail.com>
Created: November 2011
Version: 0.1
*/
#include <octave/oct.h>
#include <f77-fcn.h>
#include "common.cc"
extern "C"
{
int F77_FUNC (sb16cd, SB16CD)
(char& DICO, char& JOBD, char& JOBMR, char& JOBCF,
char& ORDSEL,
int& N, int& M, int& P,
int& NCR,
double* A, int& LDA,
double* B, int& LDB,
double* C, int& LDC,
double* D, int& LDD,
double* F, int& LDF,
double* G, int& LDG,
double* HSV,
double& TOL,
int* IWORK,
double* DWORK, int& LDWORK,
int& IWARN, int& INFO);
}
DEFUN_DLD (slsb16cd, args, nargout,
"-*- texinfo -*-\n\
Slicot SB16CD Release 5.0\n\
No argument checking.\n\
For internal use only.")
{
int nargin = args.length ();
octave_value_list retval;
if (nargin != 13)
{
print_usage ();
}
else
{
// arguments in
char dico;
char jobd;
char jobmr;
char jobcf;
char ordsel;
Matrix a = args(0).matrix_value ();
Matrix b = args(1).matrix_value ();
Matrix c = args(2).matrix_value ();
Matrix d = args(3).matrix_value ();
const int idico = args(4).int_value ();
int ncr = args(5).int_value ();
const int iordsel = args(6).int_value ();
const int ijobd = args(7).int_value ();
const int ijobmr = args(8).int_value ();
Matrix f = args(9).matrix_value ();
Matrix g = args(10).matrix_value ();
const int ijobcf = args(11).int_value ();
double tol = args(12).double_value ();
if (idico == 0)
dico = 'C';
else
dico = 'D';
if (iordsel == 0)
ordsel = 'F';
else
ordsel = 'A';
if (ijobd == 0)
jobd = 'Z';
else
jobd = 'D';
if (ijobcf == 0)
jobcf = 'L';
else
jobcf = 'R';
switch (ijobmr)
{
case 0:
jobmr = 'B';
break;
case 1:
jobmr = 'F';
break;
default:
error ("slsb16cd: argument jobmr invalid");
}
int n = a.rows (); // n: number of states
int m = b.columns (); // m: number of inputs
int p = c.rows (); // p: number of outputs
int lda = max (1, n);
int ldb = max (1, n);
int ldc = max (1, p);
int ldd;
if (jobd == 'Z')
ldd = 1;
else
ldd = max (1, p);
int ldf = max (1, m);
int ldg = max (1, n);
// arguments out
ColumnVector hsv (n);
// workspace
int liwork;
if (jobmr == 'B')
liwork = 0;
else // if JOBMR = 'F'
liwork = n;
int ldwork;
int mp;
if (jobcf == 'L')
mp = m;
else // if JOBCF = 'R'
mp = p;
ldwork = 2*n*n + max (1, 2*n*n + 5*n, n*max(m,p),
n*(n + max(n,mp) + min(n,mp) + 6));
OCTAVE_LOCAL_BUFFER (int, iwork, liwork);
OCTAVE_LOCAL_BUFFER (double, dwork, ldwork);
// error indicators
int iwarn = 0;
int info = 0;
// SLICOT routine SB16CD
F77_XFCN (sb16cd, SB16CD,
(dico, jobd, jobmr, jobcf,
ordsel,
n, m, p,
ncr,
a.fortran_vec (), lda,
b.fortran_vec (), ldb,
c.fortran_vec (), ldc,
d.fortran_vec (), ldd,
f.fortran_vec (), ldf,
g.fortran_vec (), ldg,
hsv.fortran_vec (),
tol,
iwork,
dwork, ldwork,
iwarn, info));
if (f77_exception_encountered)
error ("fwcfconred: exception in SLICOT subroutine SB16CD");
static const char* err_msg[] = {
"0: OK",
"1: eigenvalue computation failure",
"2: the matrix A-L*C is not stable",
"3: the matrix A-B*F is not stable",
"4: the Lyapunov equation for computing the "
"observability Grammian is (nearly) singular",
"5: the Lyapunov equation for computing the "
"controllability Grammian is (nearly) singular",
"6: the computation of Hankel singular values failed"};
static const char* warn_msg[] = {
"0: OK",
"1: with ORDSEL = 'F', the selected order NCR is "
"greater than the order of a minimal realization "
"of the controller.",
"2: with ORDSEL = 'F', the selected order NCR "
"corresponds to repeated singular values, which are "
"neither all included nor all excluded from the "
"reduced controller. In this case, the resulting NCR "
"is set automatically to the largest value such that "
"HSV(NCR) > HSV(NCR+1)."};
error_msg ("fwcfconred", info, 6, err_msg);
warning_msg ("fwcfconred", iwarn, 2, warn_msg);
// resize
a.resize (ncr, ncr); // Ac
g.resize (ncr, p); // Bc
f.resize (m, ncr); // Cc
// Dc = 0
// return values
retval(0) = a;
retval(1) = g;
retval(2) = f;
retval(3) = octave_value (ncr);
retval(4) = hsv;
}
return retval;
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks