[6a0e2a]: src / slsb10fd.cc  Maximize  Restore  History

Download this file

198 lines (158 with data), 5.4 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
/*
Copyright (C) 2009 - 2010 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 this program. If not, see <http://www.gnu.org/licenses/>.
H-infinity (sub)optimal state controller for a continuous-time system.
Uses SLICOT SB10FD by courtesy of NICONET e.V.
<http://www.slicot.org>
Author: Lukas Reichlin <lukas.reichlin@gmail.com>
Created: December 2009
Version: 0.2
*/
#include <octave/oct.h>
#include <f77-fcn.h>
extern "C"
{
int F77_FUNC (sb10fd, SB10FD)
(int& N, int& M, int& NP,
int& NCON, int& NMEAS,
double& GAMMA,
double* A, int& LDA,
double* B, int& LDB,
double* C, int& LDC,
double* D, int& LDD,
double* AK, int& LDAK,
double* BK, int& LDBK,
double* CK, int& LDCK,
double* DK, int& LDDK,
double* RCOND,
double& TOL,
int* IWORK,
double* DWORK, int& LDWORK,
bool* BWORK,
int& INFO);
}
int max (int a, int b)
{
if (a > b)
return a;
else
return b;
}
int max (int a, int b, int c)
{
int d = max (a, b);
return max (c, d);
}
int max (int a, int b, int c, int d)
{
int e = max (a, b);
int f = max (c, d);
return max (e, f);
}
DEFUN_DLD (slsb10fd, args, nargout, "Slicot SB10FD Release 5.0")
{
int nargin = args.length ();
octave_value_list retval;
if (nargin != 7)
{
print_usage ();
}
else
{
// arguments in
NDArray a = args(0).array_value ();
NDArray b = args(1).array_value ();
NDArray c = args(2).array_value ();
NDArray d = args(3).array_value ();
int ncon = args(4).int_value ();
int nmeas = args(5).int_value ();
double gamma = args(6).double_value ();
int n = a.rows (); // n: number of states
int m = b.columns (); // m: number of inputs
int np = c.rows (); // np: number of outputs
int lda = max (1, a.rows ());
int ldb = max (1, b.rows ());
int ldc = max (1, c.rows ());
int ldd = max (1, d.rows ());
int ldak = max (1, n);
int ldbk = max (1, n);
int ldck = max (1, ncon);
int lddk = max (1, ncon);
double tol = 0;
// arguments out
dim_vector dv_ak (2);
dv_ak(0) = ldak;
dv_ak(1) = n;
dim_vector dv_bk (2);
dv_bk(0) = ldbk;
dv_bk(1) = nmeas;
dim_vector dv_ck (2);
dv_ck(0) = ldck;
dv_ck(1) = n;
dim_vector dv_dk (2);
dv_dk(0) = lddk;
dv_dk(1) = nmeas;
dim_vector dv (1);
dv(0) = 4;
NDArray ak (dv_ak);
NDArray bk (dv_bk);
NDArray ck (dv_ck);
NDArray dk (dv_dk);
NDArray rcond (dv);
// workspace
int m2 = ncon;
int m1 = m - m2;
int np1 = np - nmeas;
int np2 = nmeas;
int liwork = max (2*max (n, m-ncon, np-nmeas, ncon), n*n);
int q = max (m1, m2, np1, np2);
int ldwork = 2*q*(3*q+2*n) + max (1, (n+q)*(n+q+6), q*(q + max (n, q, 5) + 1),
2*n*(n+2*q) + max (1, 4*q*q +
max (2*q, 3*n*n + max (2*n*q, 10*n*n+12*n+5)),
q*(3*n + 3*q + max (2*n, 4*q + max (n, q)))));
OCTAVE_LOCAL_BUFFER (int, iwork, liwork);
OCTAVE_LOCAL_BUFFER (double, dwork, ldwork);
OCTAVE_LOCAL_BUFFER (bool, bwork, 2*n);
// error indicator
int info;
// SLICOT routine SB10FD
F77_XFCN (sb10fd, SB10FD,
(n, m, np,
ncon, nmeas,
gamma,
a.fortran_vec (), lda,
b.fortran_vec (), ldb,
c.fortran_vec (), ldc,
d.fortran_vec (), ldd,
ak.fortran_vec (), ldak,
bk.fortran_vec (), ldbk,
ck.fortran_vec (), ldck,
dk.fortran_vec (), lddk,
rcond.fortran_vec (),
tol,
iwork,
dwork, ldwork,
bwork,
info));
if (f77_exception_encountered)
error ("hinfsyn: slsb10fd: exception in SLICOT subroutine SB10FD");
if (info != 0)
error ("hinfsyn: slsb10fd: SB10FD returned info = %d", info);
// return values
retval(0) = ak;
retval(1) = bk;
retval(2) = ck;
retval(3) = dk;
}
return retval;
}

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

Sign up for the SourceForge newsletter:





No, thanks