Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[5273a6]: src / sl_ab13dd.cc Maximize Restore History

Download this file

sl_ab13dd.cc    170 lines (138 with data), 4.9 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
/*
Copyright (C) 2009, 2010, 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/>.
L-infinity norm of a SS model.
Uses SLICOT AB13DD by courtesy of NICONET e.V.
<http://www.slicot.org>
Author: Lukas Reichlin <lukas.reichlin@gmail.com>
Created: November 2009
Version: 0.4
*/
#include <octave/oct.h>
#include <f77-fcn.h>
#include <complex>
#include "common.h"
extern "C"
{
int F77_FUNC (ab13dd, AB13DD)
(char& DICO, char& JOBE,
char& EQUIL, char& JOBD,
int& N, int& M, int& P,
double* FPEAK,
double* A, int& LDA,
double* E, int& LDE,
double* B, int& LDB,
double* C, int& LDC,
double* D, int& LDD,
double* GPEAK,
double& TOL,
int* IWORK, double* DWORK, int& LDWORK,
Complex* CWORK, int& LCWORK,
int& INFO);
}
// PKG_ADD: autoload ("__sl_ab13dd__", "__control_slicot_functions__.oct");
DEFUN_DLD (__sl_ab13dd__, args, nargout,
"-*- texinfo -*-\n\
Slicot AB13DD Release 5.0\n\
No argument checking.\n\
For internal use only.")
{
int nargin = args.length ();
octave_value_list retval;
if (nargin != 9)
{
print_usage ();
}
else
{
// arguments in
char dico;
char jobe;
char equil;
char jobd = 'D';
Matrix a = args(0).matrix_value ();
Matrix e = args(1).matrix_value ();
Matrix b = args(2).matrix_value ();
Matrix c = args(3).matrix_value ();
Matrix d = args(4).matrix_value ();
int discrete = args(5).int_value ();
int descriptor = args(6).int_value ();
double tol = args(7).double_value ();
const int scaled = args(8).int_value ();
if (discrete == 0)
dico = 'C';
else
dico = 'D';
if (descriptor == 0)
jobe = 'I';
else
jobe = 'G';
if (scaled == 0)
equil = 'S';
else
equil = 'N';
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 lde = max (1, n);
int ldb = max (1, n);
int ldc = max (1, p);
int ldd = max (1, p);
ColumnVector fpeak (2);
ColumnVector gpeak (2);
fpeak(0) = 0;
fpeak(1) = 1;
// workspace
int ldwork = max (1, 15*n*n + p*p + m*m + (6*n+3)*(p+m) + 4*p*m +
n*m + 22*n + 7*min(p,m));
int lcwork = max (1, (n+m)*(n+p) + 2*min(p,m) + max(p,m));
OCTAVE_LOCAL_BUFFER (int, iwork, n);
OCTAVE_LOCAL_BUFFER (double, dwork, ldwork);
OCTAVE_LOCAL_BUFFER (Complex, cwork, lcwork);
// error indicator
int info;
// SLICOT routine AB13DD
F77_XFCN (ab13dd, AB13DD,
(dico, jobe,
equil, jobd,
n, m, p,
fpeak.fortran_vec (),
a.fortran_vec (), lda,
e.fortran_vec (), lde,
b.fortran_vec (), ldb,
c.fortran_vec (), ldc,
d.fortran_vec (), ldd,
gpeak.fortran_vec (),
tol,
iwork, dwork, ldwork,
cwork, lcwork,
info));
if (f77_exception_encountered)
error ("lti: norm: __sl_ab13dd__: exception in SLICOT subroutine AB13DD");
static const char* err_msg[] = {
"0: OK",
"1: the matrix E is (numerically) singular",
"2: the (periodic) QR (or QZ) algorithm for computing "
"eigenvalues did not converge",
"3: the SVD algorithm for computing singular values did "
"not converge",
"4: the tolerance is too small and the algorithm did "
"not converge"};
error_msg ("__sl_ab13dd__", info, 4, err_msg);
// return values
retval(0) = fpeak;
retval(1) = gpeak;
}
return retval;
}