26 #if defined (HAVE_CONFIG_H)
51 double min_val =
x.min ();
54 if (min_val ==
x.xelem (i))
69 math::svd<Matrix> A_svd (
A);
75 Matrix V = A_svd.right_singular_matrix ();
82 double tol = tmp * s(0) * std::numeric_limits<double>::epsilon ();
93 retval =
V.extract (0, rank, A_nc-1, A_nc-1);
98 if (
std::abs (retval(i)) < std::numeric_limits<double>::epsilon ())
109 int maxit,
double rtol,
142 res(i) /= (1.0 +
std::abs (bin(i)));
148 bact.
resize (n_act, bin(i));
149 Wact.
resize (n_act-n_eq, i);
164 error (ee,
"qp: failed to compute eigenvalues of H");
196 double minReal = eigenvalH.
xelem (indminR);
204 math::chol<Matrix> cholH (H);
206 R = cholH.chol_matrix ();
221 p = eigenvecH.
column (indminR);
225 if (p.
transpose () * g > std::numeric_limits<double>::epsilon ())
232 lambda_tmp.
fill (0.0);
263 math::chol<Matrix> cholrH (rH, pR);
264 Matrix tR = cholrH.chol_matrix ();
305 error (ee,
"qp: failed to compute eigenvalues of rH");
317 if (p.
transpose () * g > std::numeric_limits<double>::epsilon ())
326 double max_p = abs_p.
max ();
331 if (n_act - n_eq == 0)
342 lambda_tmp = Yt * (g + H * p);
346 double min_lambda = lambda_tmp.
min ();
357 if (lambda_tmp(i) == min_lambda)
372 Aact(n_eq+i, j) = Aact(n_eq+i+1, j);
373 bact(n_eq+i) = bact(n_eq+i+1);
386 if (n_act - n_eq == n_in)
418 double tmp = tmp_row * p;
419 double res = tmp_row *
x;
423 double alpha_tmp = (bin(i) - res) / tmp;
425 if (alpha_tmp < alpha)
441 Aact = Aact.
stack (Ain.
row (is_block));
442 bact.
resize (n_act, bin(is_block));
443 Wact.
resize (n_act-n_eq, is_block);
465 lambda_tmp = Y.
transpose () * (g + H * p);
472 lambda(i) = lambda_tmp(i);
478 if (Wact(j) == i - n_eq)
480 lambda(i) = lambda_tmp(n_eq+j);
489 DEFUN (__qp__, args, ,
495 if (args.length () != 9)
499 const Matrix H (args(1).matrix_value ());
501 const Matrix Aeq (args(3).matrix_value ());
503 const Matrix Ain (args(5).matrix_value ());
505 const int maxit (args(7).int_value ());
506 const double rtol (args(8).double_value());
516 int info =
qp (H, q, Aeq, beq, Ain, bin, maxit, rtol,
x, lambda, iter);
518 return ovl (
x, lambda, info, iter);
static octave_idx_type min_index(const ColumnVector &x)
static int qp(const Matrix &H, const ColumnVector &q, const Matrix &Aeq, const ColumnVector &beq, const Matrix &Ain, const ColumnVector &bin, int maxit, double rtol, ColumnVector &x, ColumnVector &lambda, int &iter)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
Size of the specified dimension.
OCTAVE_API double max(void) const
void resize(octave_idx_type n, const double &rfv=0)
OCTAVE_API ColumnVector & fill(double val)
OCTAVE_API RowVector transpose(void) const
OCTAVE_API double min(void) const
ColumnVector extract_diag(octave_idx_type k=0) const
ComplexMatrix right_eigenvectors(void) const
ComplexColumnVector eigenvalues(void) const
OCTAVE_API Matrix pseudo_inverse(double tol=0.0) const
OCTAVE_API RowVector row(octave_idx_type i) const
OCTAVE_API Matrix stack(const Matrix &a) const
OCTAVE_API Matrix extract_n(octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const
Matrix transpose(void) const
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
OCTAVE_API ColumnVector column(octave_idx_type i) const
ColumnVector real(const ComplexColumnVector &a)
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 error(const char *fmt,...)
F77_RET_T const F77_INT const F77_INT const F77_INT const F77_DBLE const F77_DBLE F77_INT F77_DBLE * V
F77_RET_T const F77_INT F77_CMPLX * A
F77_RET_T const F77_INT const F77_INT const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE * Z
F77_RET_T const F77_DBLE * x
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.