|Determines whether or not a matrix is totally positive|
|Other toolboxes required||none|
IsTotallyPositive is a function that determines whether or not a given matrix is totally positive (i.e., all of its square submatrices have positive determinant). The input matrix can be either full or sparse.
- ITP = IsTotallyPositive(X)
- ITP = IsTotallyPositive(X,SUB_SIZES)
- ITP = IsTotallyPositive(X,SUB_SIZES,TOL)
- [ITP,WIT] = IsTotallyPositive(X,SUB_SIZES,TOL)
- X: A matrix.
- SUB_SIZES (optional, default 1:min(size(X))): A vector specifying the sizes of submatrices to be checked to have positive determinant.
- TOL (optional, default length(X)*eps(norm(X,'fro'))): The numerical tolerance used when determining positivity.
- ITP: A flag (either 1 or 0) indicating that X is or is not totally positive.
- WIT (optional): If ITP = 0 then WIT specifies a submatrix of X that has either negative or non-real determinant. More specifically, WIT is a matrix with 2 rows such that det(X(WIT(1,:),WIT(2,:))) is negative or non-real.
It is known that Vandermonde matrices are totally positive, under certain restrictions on the nodes:
In practice, this function is practical for matrices of size up to about 15-by-15.
Click on "expand" to the right to view the MATLAB source code for this function.
%% ISTOTALLYPOSITIVE Determines whether or not a matrix is totally positive
% This function has one required argument:
% X: a matrix
% ITP = IsTotallyPositive(X) is either 1 or 0, indicating that X is or
% is not totally positive (i.e., all of its square submatrices have
% positive real determinant).
% This function has two optional input arguments:
% SUB_SIZES (default 1:min(size(X)))
% TOL (default max(size(X))*eps(norm(X,'fro')))
% [ITP,WIT] = IsTotallyPositive(X,SUB_SIZES,TOL) determines whether or
% not every r-by-r submatrix of X has positive determinant, where r
% ranges over all values in the vector SUB_SIZES, and positivity is
% determined within a tolerance of TOL. If ITP = 0 then WIT is a matrix
% with two rows and r columns that specifies an r-by-r submatrix of X
% that does not have positive determinant.
% URL: http://www.qetlab.com/IsTotallyPositive
% requires: opt_args.m
% author: Nathaniel Johnston (firstname.lastname@example.org)
% package: QETLAB
% last updated: December 13, 2012
function [itp,wit] = IsTotallyPositive(X,varargin)
sX = size(X);
wit = 0;
% set optional argument defaults: sub_sizes=1:min(size(X)), tol=max(size(X))*eps(norm(X,'fro')) (same as rank)
for j = 1:length(sub_sizes)
% 1x1 determinants can be computed quickly, so do them separately
if(sub_sizes(j) == 1)
itp = 0;
wit = [r;c];
% larger determinants are slower; just loop on through!
sub_ind_r = nchoosek(1:sX(1),sub_sizes(j));
if(sX(1) == sX(2)) % nchoosek is slightly slow, so only call it once if we can get away with it
sub_ind_c = sub_ind_r;
sub_ind_c = nchoosek(1:sX(2),sub_sizes(j));
sub_ind_len_r = size(sub_ind_r,1);
sub_ind_len_c = size(sub_ind_c,1);
for kr = 1:sub_ind_len_r
for kc = 1:sub_ind_len_c
d = det(X(sub_ind_r(kr,:),sub_ind_c(kc,:)));
itp = 0;
wit = [sub_ind_r(kr,:);sub_ind_c(kc,:)];
itp = 1;