dbleAEPBAL.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1994-2012 John W. Eaton
00004 Copyright (C) 2008 Jaroslav Hajek
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include <string>
00029 
00030 #include "dbleAEPBAL.h"
00031 #include "f77-fcn.h"
00032 
00033 extern "C"
00034 {
00035   F77_RET_T
00036   F77_FUNC (dgebal, DGEBAL) (F77_CONST_CHAR_ARG_DECL,
00037                              const octave_idx_type&, double*,
00038                              const octave_idx_type&, octave_idx_type&,
00039                              octave_idx_type&, double*, octave_idx_type&
00040                              F77_CHAR_ARG_LEN_DECL);
00041 
00042   F77_RET_T
00043   F77_FUNC (dgebak, DGEBAK) (F77_CONST_CHAR_ARG_DECL,
00044                              F77_CONST_CHAR_ARG_DECL,
00045                              const octave_idx_type&, const octave_idx_type&,
00046                              const octave_idx_type&, const double*,
00047                              const octave_idx_type&, double*,
00048                              const octave_idx_type&, octave_idx_type&
00049                              F77_CHAR_ARG_LEN_DECL
00050                              F77_CHAR_ARG_LEN_DECL);
00051 }
00052 
00053 AEPBALANCE::AEPBALANCE (const Matrix& a, bool noperm, bool noscal)
00054   : base_aepbal<Matrix, ColumnVector> ()
00055 {
00056   octave_idx_type n = a.cols ();
00057 
00058   if (a.rows () != n)
00059     {
00060       (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix");
00061       return;
00062     }
00063 
00064   octave_idx_type info;
00065 
00066   scale = ColumnVector (n);
00067   double *pscale = scale.fortran_vec ();
00068 
00069   balanced_mat = a;
00070   double *p_balanced_mat = balanced_mat.fortran_vec ();
00071 
00072   job = noperm ? (noscal ? 'N' : 'S') : (noscal ? 'P' : 'B');
00073 
00074   F77_XFCN (dgebal, DGEBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
00075                              n, p_balanced_mat, n, ilo, ihi, pscale, info
00076                              F77_CHAR_ARG_LEN (1)));
00077 }
00078 
00079 Matrix
00080 AEPBALANCE::balancing_matrix (void) const
00081 {
00082   octave_idx_type n = balanced_mat.rows ();
00083   Matrix balancing_mat (n, n, 0.0);
00084   for (octave_idx_type i = 0; i < n; i++)
00085     balancing_mat.elem (i ,i) = 1.0;
00086 
00087   double *p_balancing_mat = balancing_mat.fortran_vec ();
00088   const double *pscale = scale.fortran_vec ();
00089 
00090   octave_idx_type info;
00091 
00092   char side = 'R';
00093 
00094   F77_XFCN (dgebak, DGEBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
00095                              F77_CONST_CHAR_ARG2 (&side, 1),
00096                              n, ilo, ihi, pscale, n,
00097                              p_balancing_mat, n, info
00098                              F77_CHAR_ARG_LEN (1)
00099                              F77_CHAR_ARG_LEN (1)));
00100 
00101   return balancing_mat;
00102 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines