from
slatec
by Ben Barrowes The slatec library converted into matlab functions.
[cargresult,z]=carg(z);
function [cargresult,z]=carg(z);
cargresult=[];
persistent carg ;
if isempty(cargresult), cargresult=0; end;
%***BEGIN PROLOGUE CARG
%***PURPOSE Compute the argument of a complex number.
%***LIBRARY SLATEC (FNLIB)
%***CATEGORY A4A
%***TYPE COMPLEX (CARG-C)
%***KEYWORDS ARGUMENT OF A COMPLEX NUMBER, ELEMENTARY FUNCTIONS, FNLIB
%***AUTHOR Fullerton, W., (LANL)
%***DESCRIPTION
%
% CARG(Z) calculates the argument of the complex number Z. Note
% that CARG returns a real result. If Z = X+iY, then CARG is ATAN(Y/X),
% except when both X and Y are zero, in which case the result
% will be zero.
%
%***REFERENCES (NONE)
%***ROUTINES CALLED (NONE)
%***REVISION HISTORY (YYMMDD)
% 770401 DATE WRITTEN
% 861211 REVISION DATE from Version 3.2
% 891214 Prologue converted to Version 4.0 format. (BAB)
%***end PROLOGUE CARG
%***FIRST EXECUTABLE STATEMENT CARG
cargresult = 0.0;
if( real(z)~=0. || imag(z)~=0. )
cargresult = atan2(imag(z),real(z));
end;
%
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',z); evalin('caller',[inputname(1),'=FUntemp;']); end
end
%DECK CASIN