Code covered by the BSD License  

Highlights from
slatec

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

[idamaxresult,n,dx,incx]=idamax(n,dx,incx);
function [idamaxresult,n,dx,incx]=idamax(n,dx,incx);
idamaxresult=[];
persistent dmax i ix xmag ; 

;
%***BEGIN PROLOGUE  IDAMAX
%***PURPOSE  Find the smallest index of that component of a vector
%            having the maximum magnitude.
%***LIBRARY   SLATEC (BLAS)
%***CATEGORY  D1A2
%***TYPE      doubleprecision (ISAMAX-S, IDAMAX-D, ICAMAX-C)
%***KEYWORDS  BLAS, LINEAR ALGEBRA, MAXIMUM COMPONENT, VECTOR
%***AUTHOR  Lawson, C. L., (JPL)
%           Hanson, R. J., (SNLA)
%           Kincaid, D. R., (U. of Texas)
%           Krogh, F. T., (JPL)
%***DESCRIPTION
%
%                B L A S  Subprogram
%    Description of Parameters
%
%     --Input--
%        N  number of elements in input vector(s)
%       DX  doubleprecision vector with N elements
%     INCX  storage spacing between elements of DX
%
%     --Output--
%   IDAMAX  smallest index (zero if N .LE. 0)
%
%     Find smallest index of maximum magnitude of doubleprecision DX.
%     IDAMAX = first I, I = 1 to N, to maximize ABS(DX(IX+(I-1)*INCX)),
%     where IX = 1 if INCX .GE. 0, else IX = 1+(1-N)*INCX.
%
%***REFERENCES  C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T.
%                 Krogh, Basic linear algebra subprograms for Fortran
%                 usage, Algorithm No. 539, Transactions on Mathematical
%                 Software 5, 3 (September 1979), pp. 308-323.
%***ROUTINES CALLED  (NONE)
%***REVISION HISTORY  (YYMMDD)
%   791001  DATE WRITTEN
%   890531  Changed all specific intrinsics to generic.  (WRB)
%   890531  REVISION DATE from Version 3.2
%   891214  Prologue converted to Version 4.0 format.  (BAB)
%   900821  Modified to correct problem with a negative increment.
%           (WRB)
%   920501  Reformatted the REFERENCES section.  (WRB)
%***end PROLOGUE  IDAMAX
dx_shape=size(dx);dx=reshape(dx,1,[]);
if isempty(dmax), dmax=0; end;
if isempty(xmag), xmag=0; end;
if isempty(i), i=0; end;
if isempty(ix), ix=0; end;
%***FIRST EXECUTABLE STATEMENT  IDAMAX
idamaxresult = 0;
if( n<=0 )
dx_shape=zeros(dx_shape);dx_shape(:)=dx(1:numel(dx_shape));dx=dx_shape;
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',n); evalin('caller',[inputname(1),'=FUntemp;']); end
if csnil&&~isempty(inputname(3)), assignin('caller','FUntemp',incx); evalin('caller',[inputname(3),'=FUntemp;']); end
if csnil&&~isempty(inputname(2)), assignin('caller','FUntemp',dx); evalin('caller',[inputname(2),'=FUntemp;']); end
return;
end;
idamaxresult = 1;
if( n==1 )
dx_shape=zeros(dx_shape);dx_shape(:)=dx(1:numel(dx_shape));dx=dx_shape;
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',n); evalin('caller',[inputname(1),'=FUntemp;']); end
if csnil&&~isempty(inputname(3)), assignin('caller','FUntemp',incx); evalin('caller',[inputname(3),'=FUntemp;']); end
if csnil&&~isempty(inputname(2)), assignin('caller','FUntemp',dx); evalin('caller',[inputname(2),'=FUntemp;']); end
return;
end;
%
if( incx==1 )
%
%     Code for increments equal to 1.
%
dmax = abs(dx(1));
for i = 2 : n;
xmag = abs(dx(i));
if( xmag>dmax )
idamaxresult = i;
dmax = xmag;
end;
end; i = fix(n+1);
else;
%
%     Code for increments not equal to 1.
%
ix = 1;
if( incx<0 )
ix =fix((-n+1).*incx + 1);
end;
dmax = abs(dx(ix));
ix = fix(ix + incx);
for i = 2 : n;
xmag = abs(dx(ix));
if( xmag>dmax )
idamaxresult = i;
dmax = xmag;
end;
ix = fix(ix + incx);
end; i = fix(n+1);
dx_shape=zeros(dx_shape);dx_shape(:)=dx(1:numel(dx_shape));dx=dx_shape;
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',n); evalin('caller',[inputname(1),'=FUntemp;']); end
if csnil&&~isempty(inputname(3)), assignin('caller','FUntemp',incx); evalin('caller',[inputname(3),'=FUntemp;']); end
if csnil&&~isempty(inputname(2)), assignin('caller','FUntemp',dx); evalin('caller',[inputname(2),'=FUntemp;']); end
return;
end;
dx_shape=zeros(dx_shape);dx_shape(:)=dx(1:numel(dx_shape));dx=dx_shape;
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',n); evalin('caller',[inputname(1),'=FUntemp;']); end
if csnil&&~isempty(inputname(3)), assignin('caller','FUntemp',incx); evalin('caller',[inputname(3),'=FUntemp;']); end
if csnil&&~isempty(inputname(2)), assignin('caller','FUntemp',dx); evalin('caller',[inputname(2),'=FUntemp;']); end
end
%DECK IDLOC

Contact us at files@mathworks.com