Code covered by the BSD License  

Highlights from
slatec

from slatec by Ben Barrowes
The slatec library converted into matlab functions.

[uplo,trans,diag,n,ap,x,incx]=stpsv(uplo,trans,diag,n,ap,x,incx);
function [uplo,trans,diag,n,ap,x,incx]=stpsv(uplo,trans,diag,n,ap,x,incx);
%***BEGIN PROLOGUE  STPSV
%***PURPOSE  Solve one of the systems of equations.
%***LIBRARY   SLATEC (BLAS)
%***CATEGORY  D1B4
%***TYPE      SINGLE PRECISION (STPSV-S, DTPSV-D, CTPSV-C)
%***KEYWORDS  LEVEL 2 BLAS, LINEAR ALGEBRA
%***AUTHOR  Dongarra, J. J., (ANL)
%           Du Croz, J., (NAG)
%           Hammarling, S., (NAG)
%           Hanson, R. J., (SNLA)
%***DESCRIPTION
%
%  STPSV  solves one of the systems of equations
%
%     A*x = b,   or   A'*x = b,
%
%  where b and x are n element vectors and A is an n by n unit, or
%  non-unit, upper or lower triangular matrix, supplied in packed form.
%
%  No test for singularity or near-singularity is included in this
%  routine. Such tests must be performed before calling this routine.
%
%  Parameters
%  ==========
%
%  UPLO   - CHARACTER*1.
%           On entry, UPLO specifies whether the matrix is an upper or
%           lower triangular matrix as follows:
%
%              UPLO = 'U' or 'u'   A is an upper triangular matrix.
%
%              UPLO = 'L' or 'l'   A is a lower triangular matrix.
%
%           Unchanged on exit.
%
%  TRANS  - CHARACTER*1.
%           On entry, TRANS specifies the equations to be solved as
%           follows:
%
%              TRANS = 'N' or 'n'   A*x = b.
%
%              TRANS = 'T' or 't'   A'*x = b.
%
%              TRANS = 'C' or 'c'   A'*x = b.
%
%           Unchanged on exit.
%
%  DIAG   - CHARACTER*1.
%           On entry, DIAG specifies whether or not A is unit
%           triangular as follows:
%
%              DIAG = 'U' or 'u'   A is assumed to be unit triangular.
%
%              DIAG = 'N' or 'n'   A is not assumed to be unit
%                                  triangular.
%
%           Unchanged on exit.
%
%  N      - INTEGER.
%           On entry, N specifies the order of the matrix A.
%           N must be at least zero.
%           Unchanged on exit.
%
%  AP     - REAL             array of DIMENSION at least
%           ( ( n*( n + 1))/2).
%           Before entry with  UPLO = 'U' or 'u', the array AP must
%           contain the upper triangular matrix packed sequentially,
%           column by column, so that AP( 1 ) contains a( 1, 1 ),
%           AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 )
%           respectively, and so on.
%           Before entry with UPLO = 'L' or 'l', the array AP must
%           contain the lower triangular matrix packed sequentially,
%           column by column, so that AP( 1 ) contains a( 1, 1 ),
%           AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 )
%           respectively, and so on.
%           Note that when  DIAG = 'U' or 'u', the diagonal elements of
%           A are not referenced, but are assumed to be unity.
%           Unchanged on exit.
%
%  X      - REAL             array of dimension at least
%           ( 1 + ( n - 1 )*abs( INCX ) ).
%           Before entry, the incremented array X must contain the n
%           element right-hand side vector b. On exit, X is overwritten
%           with the solution vector x.
%
%  INCX   - INTEGER.
%           On entry, INCX specifies the increment for the elements of
%           X. INCX must not be zero.
%           Unchanged on exit.
%
%***REFERENCES  Dongarra, J. J., Du Croz, J., Hammarling, S., and
%                 Hanson, R. J.  An extended set of Fortran basic linear
%                 algebra subprograms.  ACM TOMS, Vol. 14, No. 1,
%                 pp. 1-17, March 1988.
%***ROUTINES CALLED  LSAME, XERBLA
%***REVISION HISTORY  (YYMMDD)
%   861022  DATE WRITTEN
%   910605  Modified to meet SLATEC prologue standards.  Only comment
%           lines were modified.  (BKS)
%***end PROLOGUE  STPSV
%     .. Scalar Arguments ..
%     .. Array Arguments ..
persistent i info ix j jx k kk kx nounit temp zero ; 

ap_shape=size(ap);ap=reshape(ap,1,[]);
x_shape=size(x);x=reshape(x,1,[]);
%     .. Parameters ..
if isempty(zero), zero=0.0e+0 ; end;
%     .. Local Scalars ..
if isempty(temp), temp=0; end;
if isempty(i), i=0; end;
if isempty(info), info=0; end;
if isempty(ix), ix=0; end;
if isempty(j), j=0; end;
if isempty(jx), jx=0; end;
if isempty(k), k=0; end;
if isempty(kk), kk=0; end;
if isempty(kx), kx=0; end;
if isempty(nounit), nounit=false; end;
%     .. External Functions ..
%     .. External Subroutines ..
%***FIRST EXECUTABLE STATEMENT  STPSV
%
%     Test the input parameters.
%
info = 0;
if( ~lsame(uplo,'U') && ~lsame(uplo,'L') )
info = 1;
elseif ( ~lsame(trans,'N') && ~lsame(trans,'T') &&~lsame(trans,'C') ) ;
info = 2;
elseif ( ~lsame(diag,'U') && ~lsame(diag,'N') ) ;
info = 3;
elseif( n<0 ) ;
info = 4;
elseif( incx==0 ) ;
info = 7;
end;
if( info~=0 )
[dumvar1,info]=xerbla('STPSV ',info);
ap_shape=zeros(ap_shape);ap_shape(:)=ap(1:numel(ap_shape));ap=ap_shape;
x_shape=zeros(x_shape);x_shape(:)=x(1:numel(x_shape));x=x_shape;
return;
end;
%
%     Quick return if possible.
%
if( n==0 )
ap_shape=zeros(ap_shape);ap_shape(:)=ap(1:numel(ap_shape));ap=ap_shape;
x_shape=zeros(x_shape);x_shape(:)=x(1:numel(x_shape));x=x_shape;
return;
end;
%
[nounit ,diag]=lsame(diag,'N');
%
%     Set up the start point in X if the increment is not unity. This
%     will be  ( N - 1 )*INCX  too small for descending loops.
%
if( incx<=0 )
kx = fix(1 -(n-1).*incx);
elseif( incx~=1 ) ;
kx = 1;
end;
%
%     Start the operations. In this version the elements of AP are
%     accessed sequentially with one pass through AP.
%
if( lsame(trans,'N') )
%
%        Form  x := inv( A )*x.
%
if( lsame(uplo,'U') )
kk =fix(fix((n.*(n+1))./2));
if( incx==1 )
for j = n : -1: 1 ;
if( x(j)~=zero )
if( nounit )
x(j) = x(j)./ap(kk);
end;
temp = x(j);
k = fix(kk - 1);
for i = j - 1 : -1: 1 ;
x(i) = x(i) - temp.*ap(k);
k = fix(k - 1);
end; i = fix(1 -1);
end;
kk = fix(kk - j);
end; j = fix(1 -1);
else;
jx = fix(kx +(n-1).*incx);
for j = n : -1: 1 ;
if( x(jx)~=zero )
if( nounit )
x(jx) = x(jx)./ap(kk);
end;
temp = x(jx);
ix = fix(jx);
for k = kk - 1 : -1: kk - j + 1 ;
ix = fix(ix - incx);
x(ix) = x(ix) - temp.*ap(k);
end; k = fix(kk - j + 1 -1);
end;
jx = fix(jx - incx);
kk = fix(kk - j);
end; j = fix(1 -1);
end;
else;
kk = 1;
if( incx==1 )
for j = 1 : n;
if( x(j)~=zero )
if( nounit )
x(j) = x(j)./ap(kk);
end;
temp = x(j);
k = fix(kk + 1);
for i = j + 1 : n;
x(i) = x(i) - temp.*ap(k);
k = fix(k + 1);
end; i = fix(n+1);
end;
kk = fix(kk +(n-j+1));
end; j = fix(n+1);
else;
jx = fix(kx);
for j = 1 : n;
if( x(jx)~=zero )
if( nounit )
x(jx) = x(jx)./ap(kk);
end;
temp = x(jx);
ix = fix(jx);
for k = kk + 1 : kk + n - j;
ix = fix(ix + incx);
x(ix) = x(ix) - temp.*ap(k);
end; k = fix(kk + n - j+1);
end;
jx = fix(jx + incx);
kk = fix(kk +(n-j+1));
end; j = fix(n+1);
end;
end;
%
%        Form  x := inv( A' )*x.
%
elseif ( lsame(uplo,'U') ) ;
kk = 1;
if( incx==1 )
for j = 1 : n;
temp = x(j);
k = fix(kk);
for i = 1 : j - 1;
temp = temp - ap(k).*x(i);
k = fix(k + 1);
end; i = fix(j - 1+1);
if( nounit )
temp = temp./ap(kk+j-1);
end;
x(j) = temp;
kk = fix(kk + j);
end; j = fix(n+1);
else;
jx = fix(kx);
for j = 1 : n;
temp = x(jx);
ix = fix(kx);
for k = kk : kk + j - 2;
temp = temp - ap(k).*x(ix);
ix = fix(ix + incx);
end; k = fix(kk + j - 2+1);
if( nounit )
temp = temp./ap(kk+j-1);
end;
x(jx) = temp;
jx = fix(jx + incx);
kk = fix(kk + j);
end; j = fix(n+1);
end;
else;
kk =fix(fix((n.*(n+1))./2));
if( incx==1 )
for j = n : -1: 1 ;
temp = x(j);
k = fix(kk);
for i = n : -1: j + 1 ;
temp = temp - ap(k).*x(i);
k = fix(k - 1);
end; i = fix(j + 1 -1);
if( nounit )
temp = temp./ap(kk-n+j);
end;
x(j) = temp;
kk = fix(kk -(n-j+1));
end; j = fix(1 -1);
else;
kx = fix(kx +(n-1).*incx);
jx = fix(kx);
for j = n : -1: 1 ;
temp = x(jx);
ix = fix(kx);
for k = kk : -1: kk -(n-(j+1)) ;
temp = temp - ap(k).*x(ix);
ix = fix(ix - incx);
end; k = fix(kk -(n-(j+1)) -1);
if( nounit )
temp = temp./ap(kk-n+j);
end;
x(jx) = temp;
jx = fix(jx - incx);
kk = fix(kk -(n-j+1));
end; j = fix(1 -1);
end;
end;
%
%
%     end of STPSV .
%
ap_shape=zeros(ap_shape);ap_shape(:)=ap(1:numel(ap_shape));ap=ap_shape;
x_shape=zeros(x_shape);x_shape(:)=x(1:numel(x_shape));x=x_shape;
end
%DECK STRCO

Contact us