26 #if defined (HAVE_CONFIG_H)
49 DEFUN (balance, args, nargout,
94 int nargin = args.length ();
96 if (nargin < 1 || nargin > 3 || nargout < 0)
102 bool AEPcase = nargin == 1 || args(1).is_string ();
107 if (
nn != args(0).columns ())
110 bool isfloat = args(0).is_single_type ()
111 || (! AEPcase && args(1).is_single_type ());
113 bool complex_case = args(0).iscomplex ()
114 || (! AEPcase && args(1).iscomplex ());
125 fcaa = args(0).float_complex_matrix_value ();
127 faa = args(0).float_matrix_value ();
132 caa = args(0).complex_matrix_value ();
134 aa = args(0).matrix_value ();
145 std::string a1s = args(1).string_value ();
146 noperm = a1s ==
"noperm" || a1s ==
"S";
147 noscal = a1s ==
"noscal" || a1s ==
"P";
155 math::aepbalance<FloatComplexMatrix> result (fcaa, noperm, noscal);
157 if (nargout == 0 || nargout == 1)
158 retval =
ovl (result.balanced_matrix ());
159 else if (nargout == 2)
160 retval =
ovl (result.balancing_matrix (),
161 result.balanced_matrix ());
163 retval =
ovl (result.scaling_vector (),
164 result.permuting_vector (),
165 result.balanced_matrix ());
169 math::aepbalance<FloatMatrix> result (faa, noperm, noscal);
171 if (nargout == 0 || nargout == 1)
172 retval =
ovl (result.balanced_matrix ());
173 else if (nargout == 2)
174 retval =
ovl (result.balancing_matrix (),
175 result.balanced_matrix ());
177 retval =
ovl (result.scaling_vector (),
178 result.permuting_vector (),
179 result.balanced_matrix ());
186 math::aepbalance<ComplexMatrix> result (caa, noperm, noscal);
188 if (nargout == 0 || nargout == 1)
189 retval =
ovl (result.balanced_matrix ());
190 else if (nargout == 2)
191 retval =
ovl (result.balancing_matrix (),
192 result.balanced_matrix ());
194 retval =
ovl (result.scaling_vector (),
195 result.permuting_vector (),
196 result.balanced_matrix ());
200 math::aepbalance<Matrix> result (aa, noperm, noscal);
202 if (nargout == 0 || nargout == 1)
203 retval =
ovl (result.balanced_matrix ());
204 else if (nargout == 2)
205 retval =
ovl (result.balancing_matrix (),
206 result.balanced_matrix ());
208 retval =
ovl (result.scaling_vector (),
209 result.permuting_vector (),
210 result.balanced_matrix ());
218 warning (
"balance: used GEP, should have two output arguments");
224 bal_job = args(2).xstring_value (
"balance: OPT argument must be a string");
226 if ((
nn != args(1).columns ()) || (
nn != args(1).rows ()))
237 fcbb = args(1).float_complex_matrix_value ();
239 fbb = args(1).float_matrix_value ();
244 cbb = args(1).complex_matrix_value ();
246 bb = args(1).matrix_value ();
254 math::gepbalance<FloatComplexMatrix> result (fcaa, fcbb, bal_job);
259 retval(3) = result.balanced_matrix2 ();
263 retval(2) = result.balanced_matrix ();
264 retval(1) = result.balancing_matrix2 ();
265 retval(0) = result.balancing_matrix ();
269 retval(1) = result.balancing_matrix2 ();
273 retval(0) = result.balancing_matrix ();
277 error (
"balance: invalid number of output arguments");
283 math::gepbalance<FloatMatrix> result (faa, fbb, bal_job);
288 retval(3) = result.balanced_matrix2 ();
292 retval(2) = result.balanced_matrix ();
293 retval(1) = result.balancing_matrix2 ();
294 retval(0) = result.balancing_matrix ();
298 retval(1) = result.balancing_matrix2 ();
302 retval(0) = result.balancing_matrix ();
306 error (
"balance: invalid number of output arguments");
315 math::gepbalance<ComplexMatrix> result (caa, cbb, bal_job);
320 retval(3) = result.balanced_matrix2 ();
324 retval(2) = result.balanced_matrix ();
325 retval(1) = result.balancing_matrix2 ();
326 retval(0) = result.balancing_matrix ();
330 retval(1) = result.balancing_matrix2 ();
334 retval(0) = result.balancing_matrix ();
338 error (
"balance: invalid number of output arguments");
344 math::gepbalance<Matrix> result (aa, bb, bal_job);
349 retval(3) = result.balanced_matrix2 ();
353 retval(2) = result.balanced_matrix ();
354 retval(1) = result.balancing_matrix2 ();
355 retval(0) = result.balancing_matrix ();
359 retval(1) = result.balancing_matrix2 ();
363 retval(0) = result.balancing_matrix ();
367 error (
"balance: invalid number of output arguments");
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void print_usage(void)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning(const char *fmt,...)
void error(const char *fmt,...)
void err_square_matrix_required(const char *fcn, const char *name)
void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.