[Previous]
[Next]
NAME:
LA_DETERM
PURPOSE:
This function computes the determinant of an N by N array.
CALLING SEQUENCE:
Result = LA_DETERM(A)
INPUTS:
A: An N by N array of any numeric type. A may be complex.
KEYWORD PARAMETERS:
CHECK: If set to a non-zero value, A is checked for singularity.
The determinant of a singular array is returned as zero if
this keyword is set. Run-time errors may result if A is
singular and this keyword is not set.
DOUBLE: If set to a non-zero value, computations are done in
double precision arithmetic.
ZERO: Use this keyword to set the value of floating-point
zero. A floating-point zero on the main diagonal of
a triangular matrix results in a zero determinant.
For single-precision inputs, the default value is
1.0e-6. For double-precision inputs, the default value
is 1.0e-12.
EXAMPLE:
Define an array (a).
a = [[ 2.0, 1.0, 1.0], $
[ 4.0, -6.0, 0.0], $
[-2.0, 7.0, 2.0]]
Compute the determinant.
result = LA_DETERM(a)
PROCEDURE:
LU decomposition is used to represent the input array in
triangular form. The determinant is computed as the product
of diagonal elements of the triangular form. Row interchanges
are tracked during the LU decomposition to ensure the correct
sign, + or - .
REFERENCE:
ADVANCED ENGINEERING MATHEMATICS (seventh edition)
Erwin Kreyszig
ISBN 0-471-55380-8
Anderson et al., LAPACK Users' Guide, 3rd ed., SIAM, 1999.
MODIFICATION HISTORY:
Written by: CT, RSI, December 2001. Similar to determ.pro but
uses LAPACK LA_LUDC for complex input.
[Previous]
[Next]
NAME:
LA_LINEAR_EQUATION
PURPOSE:
This function uses LU decomposition to solve a system of
linear equations, Ax = B, and provides optional error bounds and backward
error estimate.
The LA_LINEAR_EQUATION function may also be used to solve for
multiple systems of linear equations, with each column of B representing a
different set of equations. In this case, the result is a k-by-n array
where each of the k columns represents the improved
solution vector for that set of equations
CALLING SEQUENCE:
Result = LA_LINEAR_EQUATION(Array, B)
INPUTS:
Array: An n-by-n array.
B: An n-element vector, or a k-by-n array.
KEYWORD PARAMETERS:
BACKWARD_ERROR: On output, will contain the estimated backward error
bound for each linear system.
DOUBLE: Set this keyword to force the computation to be done in
double-precision arithmetic.
FORWARD_ERROR: On output, will contain the estimated forward error
bound for each linear system.
STATUS: Set this keyword to return the status of the LU decomposition.
Otherwise, error messages are output to the screen.
Possible values are:
STATUS = 0: The computation was successful.
STATUS > 0: One of the diagonal elements of U was zero.
The STATUS value specifies which diagonal was zero.
If STATUS > 0 then the Result will be a scalar zero.
OUTPUT:
The result is an n-element vector (or a k-by-n array)
whose type is identical to A.
PROCEDURE:
Uses LA_LUDC, LA_LUSOL, LA_LUMPROVE.
EXAMPLE:
MODIFICATION HISTORY:
Written by: CT, RSI, October 2001.
[Previous]
[Next]
NAME:
LABEL_DATE
PURPOSE:
This function labels axes with dates and times.
CATEGORY:
Plotting.
CALLING SEQUENCE:
To set up:
dummy = LABEL_DATE(DATE_FORMAT='string')
To use:
PLOT, x, y, XTICKFORMAT='LABEL_DATE'
INPUTS:
No explicit user defined inputs. When called from the plotting
routines, the input parameters are (Axis, Index, Value [, Level])
KEYWORD PARAMETERS:
DATE_FORMAT: a format string which may contain the following:
%M for month
%N for month (2 digit abbr)
%D for day of month,
%Y for 4 digit year.
%Z for last two digits of year.
%W for day of week
For time:
%A for AM or PM
%H for Hours, 2 digits.
%I for mInutes, 2 digits.
%S for Seconds, 2 digits.
%0--%9 following %S, indicates digits after decimal point.
%% is %.
If a time format string is specified, the time of day
will be rounded to the nearest least significant time format
specified. E.g. if the format '%H:%I' is specified
(hours:minutes) the time is rounded to the nearest minute.
Other characters are passed directly thru.
For example, '%M %D, %Y' prints DEC 11, 1993
'%M %2Y' yields DEC 93
'%D-%M' yields 11-DEC
'%D/%N/%Y' yields 11/12/1993
'%M!C%Y' yields DEC on the top line, 1993 on
the bottom (!C is the new line graphic command).
AM_PM: The names for AM or PM. The default is ["am","pm"]
DAYS_OF_WEEK: The names of the days, a seven-element string array.
The default is [Sun, Mon, Tue, Wed, Thu, Fri, Sat].
MONTHS: The names of the months, a twelve element string array.
The default is [Jan, Feb,..., Dec].
OFFSET: Set this keyword to a value representing the offset to be added
to each tick value before conversion to a label. This keyword
is usually used when your axis values are measured relative to
a certain starting time. In this case, OFFSET should be set to
the Julian date of the starting time.
ROUND_UP: Set this keyword to force times to be rounded up to the
smallest time unit that is present in the DATE_FORMAT string.
The default is for times to be truncated to the
smallest time unit.
OUTPUTS:
The date string to be plotted.
CALLS: ***
LABEL_DATE_CONVERT_FORMAT
COMMON BLOCKS:
LABEL_DATE_COM.
RESTRICTIONS:
Uses a common block, so only one date axis may be simultaneously active.
PROCEDURE:
Straightforward.
For an alternative way to label a plot axis with dates, refer to
the C() format code accepted within format strings (applicable via
the [XYZ]TICKFORMAT keywords). This format code was
introduced in IDL 5.2.
EXAMPLE:
For example, to plot from Jan 1, 1993, to July 12, 1994:
Start_date = julday(1, 1, 1993)
End_date = julday(7, 12, 1994)
Dummy = LABEL_DATE(DATE_FORMAT='%N/%D') ;Simple mm/dd
x = findgen(end_date+1 - start_date) + start_date ;Time axis
PLOT, x, sqrt(x), XTICKFORMAT = 'LABEL_DATE', XSTYLE=1
(Plot with X axis style set to exact.)
Example with times:
For example, to plot from 3PM, Jan 1, 1993, to 5AM, Jan 3,
1993:
Start_date = Julday(1,1,1993) ;Also starting offset
Start_time = (3+12)/24. ;Starting_time less offset
End_time = (Julday(1,3,1993) - Start_date) + 5./24. ;Ending
;date/time - offset, note that the order of operations is
; important to avoid loss of precision.
Dummy = LABEL_DATE(DATE_FORMAT='%D %M!C%H:%I', $
offset=Start_date) ;MMM NN <new line> HH:MM format
x = findgen(20) * (End_time - Start_time) / 19 + start_time ;Time axis
PLOT, x, sqrt(x), XTICKFORMAT = 'LABEL_DATE', XSTYLE=1
MODIFICATION HISTORY:
DMS, RSI. April, 1993. Written.
DMS, RSI. March, 1997. Added Time format.
DMS, RSI. Jan, 1999. Rounded least significant time unit
CT, RSI. May 2000. Completely rewrote to use calendar format codes.
Added Level argument for new date/time TICKUNITS.
Added AM_PM and DAYS_OF_WEEK keywords, '%A' and '%W' codes.
[Previous]
[Next]
NAME:
LADFIT
PURPOSE:
This function fits the paired data {X(i), Y(i)} to the linear model,
y = A + Bx, using a "robust" least absolute deviation method. The
result is a two-element vector containing the model parameters, A
and B.
CATEGORY:
Statistics.
CALLING SEQUENCE:
Result = LADFIT(X, Y)
INPUTS:
X: An n-element vector of type integer, float or double.
Y: An n-element vector of type integer, float or double.
KEYWORD PARAMETERS:
ABSDEV: Use this keyword to specify a named variable which returns the
mean absolute deviation for each data-point in the y-direction.
DOUBLE: If set to a non-zero value, computations are done in double
precision arithmetic.
CALLS: ***
MDFUNC
EXAMPLE:
Define two n-element vectors of paired data.
x = [-3.20, 4.49, -1.66, 0.64, -2.43, -0.89, -0.12, 1.41, $
2.95, 2.18, 3.72, 5.26]
y = [-7.14, -1.30, -4.26, -1.90, -6.19, -3.98, -2.87, -1.66, $
-0.78, -2.61, 0.31, 1.74]
Compute the model parameters, A and B.
result = ladfit(x, y, absdev = absdev)
The result should be the two-element vector:
[-3.15301, 0.930440]
The keyword parameter should be returned as:
absdev = 0.636851
REFERENCE:
Numerical Recipes, The Art of Scientific Computing (Second Edition)
Cambridge University Press, 2nd Edition.
ISBN 0-521-43108-5
This is adapted from the routine MEDFIT described in:
Fitting a Line by Minimizing Absolute Deviation, Page 703.
MODIFICATION HISTORY:
Written by: GGS, RSI, September 1994
Modified: GGS, RSI, July 1995
Corrected an infinite loop condition that occured when
the X input parameter contained mostly negative data.
Modified: GGS, RSI, October 1996
If least-absolute-deviation convergence condition is not
satisfied, the algorithm switches to a chi-squared model.
Modified keyword checking and use of double precision.
Modified: GGS, RSI, November 1996
Fixed an error in the computation of the median with
even-length input data. See EVEN keyword to MEDIAN.
Modified: DMS, RSI, June 1997
Simplified logic, remove SIGN and MDfunc2 functions.
Modified: RJF, RSI, Jan 1999
Fixed the variance computation by adding some double
conversions. This prevents the function from generating
NaNs on some specific datasets (bug 11680).
Modified: CT, RSI, July 2002: Convert inputs to float or double.
Change constants to double precision if necessary.
CT, March 2004: Check for quick return if we found solution.
[Previous]
[Next]
NAME:
LAGUERRE
PURPOSE:
This function returns the value of the associated Laguerre polynomial
L(N,K)[x], which is a solution to the differential equation,
xy" + (k + 1 - x)y' + ny = 0.
CATEGORY:
Special Math Functions
CALLING SEQUENCE:
Result = LAGUERRE(X, N [, K] [, COEFFICIENTS=coefficients] [, /DOUBLE])
INPUTS:
X: The value at which L(N,K) is evaluated.
X can be either a scalar or an array of any basic type except string.
If X is double-precision floating-point, complex, or double-precision
complex, the result is of the same type. Otherwise, the result is
single-precision floating-point.
N: An integer, N >= 0, specifying the order of L(N,K).
K: An integer specifying the order K of L(N,K). If K is not specified then
the default K=0 is used and the Laguerre polynomial, L(N)[x],
is returned.
KEYWORD PARAMETERS:
COEFFICIENTS: Set this keyword to a named variable that
will contain the polynomial coefficients in the expansion,
c[0] + c[1]*x + c[2]*x^2 + ...
DOUBLE: Set this keyword to force the computation to be done using
double-precision arithmetic.
OUTPUT:
The result returned by LAGUERRE is a scalar or array that has the
same dimensions as the input array X.
CALLS: ***
GAMMA
EXAMPLE:
The radial component of the hydrogen atom wavefunction is proportional to,
r^l e^(-r/2) L(n-l-1,2l+1)[r]
where r is the normalized radial coordinate, n is the energy state,
and l is the orbital angular spin number (Eisberg and Resnick, 1985:
Quantum Physics of Atoms, Molecules, Solids, Nuclei, and Particles,
Second edition. J.Wiley & Sons, pp. N3-N5).
To find the radial component of the hydrogen 3s state:
r = FINDGEN(101)/5.
n = 3 ; energy state
l = 0 ; "s" state
radial = LAGUERRE(r, n - l - 1, 2*l + 1, COEFF=coeff)
PLOT, r, radial*(r^l)*EXP(-r/2), TITLE='Hydrogen 3s radial component'
PRINT, "Coefficients c[0] + c[1]r + c[2]r^2 + ... = ",coeff
IDL prints:
Coefficients c[0] + c[1]r + c[2]r^2 + ... = 3.00000 -3.00000 0.500000
MODIFICATION HISTORY:
Written by: CT, RSI, March 2000.
[Previous]
[Next]
NAME:
LEEFILT
PURPOSE:
Performs the Lee filter algorithm on an image array using a
box of size 2N+1. This function can also be used on vectors.
CATEGORY:
E3 Smoothing (image).
CALLING SEQUENCE:
Result = LEEFILT(A [, N, Sig])
INPUTS:
A: The input image array or one-dimensional vector.
OPTIONAL INPUT PARAMETERS:
N: The size of the filter box is 2N+1. The default value is 5.
Sig: Estimate of the standard deviation. The default is 5.
If Sig is negative the procedure requests a value to be
entered, and displays the resulting image or vector. This
cycle continues until a zero value of Sig is entered.
KEYWORDS:
EXACT: Use this keyword to use a more accurate, but much slower
Lee filter algorithm. Recommended when N > ~7.
DOUBLE = Set this keyword to force the computations to be done
in double-precision arithmetic.
OUTPUTS:
The filtered image or vector is returned.
CALLS: ***
LEE_FILTER_EXACT, LEE_FILTER_FAST
COMMON BLOCKS:
None.
SIDE EFFECTS:
Displays the filtered image in an IDL window using TVSCL or PLOT if
Sig is negative.
RESTRICTIONS:
None.
PROCEDURE:
The LEE (Optical Engineering, Vol 25, No 5, Pg 636-643, May 1986)
technique smooths additive image noise by generating statistics in
a local neighborhood and comparing them to the expected values.
MODIFICATION HISTORY:
Written, 24-Nov-1982, by R. A. Howard, Naval Research Lab,
Washington, DC 20375
Modified, 30-May-1996, SVP. Modifed to match 1986 algorithm &
Added /EXACT at user suggestion.
Added PLOT for vector support.
CT, RSI, May 2000: Added double-precision support.
[Previous]
[Next]
NAME:
LINFIT
PURPOSE:
This function fits the paired data {X(i), Y(i)} to the linear model,
y = A + Bx, by minimizing the chi-square error statistic. The result
is a two-element vector containing the model parameters,[A,B].
CATEGORY:
Statistics.
CALLING SEQUENCE:
Result = LINFIT(X, Y)
INPUTS:
X: An n-element vector of type integer, float or double.
Y: An n-element vector of type integer, float or double.
KEYWORD PARAMETERS:
CHISQ: Use this keyword to specify a named variable which returns the
chi-square error statistic as the sum of squared errors between
Y(i) and A + BX(i). If individual standard deviations are
supplied, then the chi-square error statistic is computed as
the sum of squared errors divided by the standard deviations.
COVAR: Set this keyword to a named variable that will contain the
covariance matrix of the fitted coefficients.
DOUBLE: If set to a non-zero value, computations are done in double
precision arithmetic.
MEASURE_ERRORS: Set this keyword to a vector containing standard
measurement errors for each point Y[i]. This vector must be the same
length as X and Y.
Note - For Gaussian errors (e.g. instrumental uncertainties),
MEASURE_ERRORS should be set to the standard
deviations of each point in Y. For Poisson or statistical weighting
MEASURE_ERRORS should be set to sqrt(Y).
PROB: Use this keyword to specify a named variable which returns the
probability that the computed fit would have a value of CHISQR
or greater. If PROB is greater than 0.1, the model parameters
are "believable". If PROB is less than 0.1, the accuracy of the
model parameters is questionable.
SIGMA: Use this keyword to specify a named variable which returns a
two-element vector of probable uncertainties for the model par-
ameters, [SIG_A,SIG_B].
Note: if MEASURE_ERRORS is omitted, then you are assuming that the
linear fit is the correct model. In this case,
SIGMA is multiplied by SQRT(CHISQ/(N-M)), where N is the
number of points in X. See section 15.2 of Numerical Recipes
in C (Second Edition) for details.
YFIT: Set this keyword to a named variable that will contain the
vector of calculated Y values.
CALLS: ***
IGAMMA
EXAMPLE:
Define two n-element vectors of paired data.
x = [-3.20, 4.49, -1.66, 0.64, -2.43, -0.89, -0.12, 1.41, $
2.95, 2.18, 3.72, 5.26]
y = [-7.14, -1.30, -4.26, -1.90, -6.19, -3.98, -2.87, -1.66, $
-0.78, -2.61, 0.31, 1.74]
Define a vector of standard deviations with a constant value of 0.85
sdev = replicate(0.85, n_elements(x))
Compute the model parameters, A and B.
result = linfit(x, y, chisq = chisq, prob = prob, sdev = sdev)
The result should be the two-element vector:
[-3.44596, 0.867329]
The keyword parameters should be returned as:
chisq = 11.4998, prob = 0.319925
REFERENCE:
Numerical Recipes, The Art of Scientific Computing (Second Edition)
Cambridge University Press
ISBN 0-521-43108-5
MODIFICATION HISTORY:
Written by: GGS, RSI, September 1994
LINFIT is based on the routines: fit.c, gammq.c, gser.c,
and gcf.c described in section 15.2 of Numerical Recipes,
The Art of Scientific Computing (Second Edition), and is
used by permission.
Modified: SVP, RSI, June 1996
Changed SIG_AB to SIGMA to be consistant with the other
fitting functions. Changed CHISQR to CHISQ in the docs
for the same reason. Note that the chisqr and the SIG_AB
keywords are left for backwards compatibility.
Modified: GGS, RSI, October 1996
Modified keyword checking and use of double precision.
Added DOUBLE keyword.
Modified: CT, RSI, July 2000: Added COVAR, MEASURE_ERRORS, YFIT keywords.
[Previous]
[Next]
NAME:
LL_ARC_DISTANCE
PURPOSE:
This function returns the longitude and latitude [lon, lat] of
a point a given arc distance (-pi <= Arc_Dist <= pi), and azimuth (Az),
from a specified location Lon_lat0.
CATEGORY:
Mapping, geography.
CALLING SEQUENCE:
Result = LL_ARC_DISTANCE(Lon_lat0, Arc_Dist, Az)
INPUTS:
Lon_lat0: A 2-element vector containing the longitude and latitude
of the starting point. Values are assumed to be in radians
unless the keyword DEGREES is set.
Arc_Dist: The arc distance from Lon_lat0. The value must be between
-!PI and +!PI. To express distances in arc units, divide
by the radius of the globe expressed in the original units.
For example, if the radius of the earth is 6371 km, divide
the distance in km by 6371 to obtain the arc distance.
Az: The azimuth from Lon_lat0. The value is assumed to be in
radians unless the keyword DEGREES is set.
KEYWORD PARAMETERS:
DEGREES: Set this keyword to express all measurements and
results in degrees.
OUTPUTS:
This function returns a two-element vector containing the
longitude and latitude of the resulting point. Values are
in radians unless the keyword DEGREES is set.
PROCEDURE:
Formula from Map Projections - a working manual. USGS paper
1395. Equations (5-5) and (5-6).
EXAMPLE:
Lon_lat0 = [1.0, 2.0] ; Initial point specified in radians
Arc_Dist = 2.0 ; Arc distance in radians
Az = 1.0 ; Azimuth in radians
Result = LL_ARC_DISTANCE(Lon_lat0, Arc_Dist, Az)
PRINT, Result
2.91415 -0.622234
MODIFICATION HISTORY:
DMS, Aug, 1992. Written.
DJC, Jun, 1994. Added test for zero arc distance.
Renamed "dist" variable to "arc_dist" for
compatibility with IDL "Dist" function.
[Previous]
[Next]
NAME:
LMFIT
PURPOSE:
Non-linear least squares fit to a function of an arbitrary
number of parameters. The function may be any non-linear
function. If available, partial derivatives can be calculated by
the user function, else this routine will estimate partial derivatives
with a forward difference approximation.
CATEGORY:
E2 - Curve and Surface Fitting.
CALLING SEQUENCE:
Result = LMFIT(X, Y, A)
INPUTS:
X: A row vector of independent variables. This routine does
not manipulate or use values in X, it simply passes X
to the user-written function.
Y: A row vector containing the dependent variable.
A: A vector that contains the initial estimate for each parameter.
KEYWORDS:
ALPHA: The value of the Curvature matrix upon exit.
CHISQ: Sum of squared errors divided by MEASURE_ERRORS if specified.
CONVERGENCE: Returns 1 if the fit converges, 0 if it does
not meet the convergence criteria in ITMAX iterations,
or -1 if a singular matrix is encountered.
If CONVERGENCE is not then any error messages will be
output.
COVAR: Covariance matrix of the coefficients.
DOUBLE: if set, force computations to be in double precision.
FITA: A vector, with as many elements as A, which contains a Zero for
each fixed parameter, and a non-zero value for elements of A to
fit. If not supplied, all parameters are taken to be non-fixed.
FUNCTION_NAME: The name of the function (actually, a procedure) to
fit. If omitted, "LMFUNCT" is used. The procedure must be written as
described under RESTRICTIONS, below.
ITMAX: Minimum number of iterations. Default = 50.
ITER: The actual number of iterations which were performed
MEASURE_ERRORS: Set this keyword to a vector containing standard
measurement errors for each point Y[i]. This vector must be the same
length as X and Y.
Note - For Gaussian errors (e.g. instrumental uncertainties),
MEASURE_ERRORS should be set to the standard
deviations of each point in Y. For Poisson or statistical weighting
MEASURE_ERRORS should be set to sqrt(Y).
SIGMA: The 1-sigma error estimates of the returned parameters,
SIGMA=SQRT(VARIANCE).
Note: if MEASURE_ERRORS is omitted, then you are assuming that
your model is correct. In this case,
SIGMA is multiplied by SQRT(CHISQ/(N-M)), where N is the
number of points in X. See section 15.2 of Numerical Recipes
in C (Second Edition) for details.
TOL: The convergence tolerance. The routine returns when the
relative decrease in chi-squared is less than TOL in an interation.
Default = 1.e-6 for single-precision or 1d-12 for double-precision.
Note - The WEIGHTS keyword is obsolete. New code should use MEASURE_ERRORS.
WEIGHTS: A vector of weights for Y[i]. This vector must be the same
length as X and Y. The default is no weighting.
Note: The error for each term is weighted by Weight[i] when computing the
fit. Gaussian or instrumental uncertianties should be weighted as
Weight = 1/Sigma where Sigma is the measurement error or standard
deviations of Y. For Poisson or statistical weighting use
Weight=1/sqrt(Y), since Sigma=sqrt(Y).
OUTPUTS:
Returns a vector containing the fitted function evaluated at the
input X values. The final estimates for the coefficients are
returned in the input vector A.
SIDE EFFECTS:
The vector A is modified to contain the final estimates for the
parameters.
RESTRICTIONS:
The function to be fit must be defined and called LMFUNCT,
unless the FUNCTION_NAME keyword is supplied. This function,
must accept a single value of X (the independent variable), and A
(the fitted function's parameter values), and return an
array whose first (zeroth) element is the evalutated function
value, and next n_elements(A) elements are the partial derivatives
with respect to each parameter in A.
If X is passed in as a double, the returned vector MUST be of
type double as well. Likewise, if X is a float, the returned
vector must also be of type float.
For example, here is the default LMFUNCT in the IDL User's Libaray.
which is called as : out_array = LMFUNCT( X, A )
function lmfunct,x,a
;Return a vector appropriate for LMFIT
;
;The function being fit is of the following form:
; F(x) = A(0) * exp( A(1) * X) + A(2) = bx+A(2)
;
;dF/dA(0) is dF(x)/dA(0) = exp(A(1)*X)
;dF/dA(1) is dF(x)/dA(1) = A(0)*X*exp(A(1)*X) = bx * X
;dF/dA(2) is dF(x)/dA(2) = 1.0
;
;return,[[F(x)],[dF/dA(0)],[dF/dA(1)],[dF/dA(2)]]
;
;Note: returning the required function in this manner
; ensures that if X is double the returned vector
; is also of type double. Other methods, such as
; evaluating size(x) are also valid.
bx=A(0)*exp(A(1)*X)
return,[ [bx+A(2)], [exp(A(1)*X)], [bx*X], [1.0] ]
end
PROCEDURE:
Based upon "MRQMIN", least squares fit to a non-linear
function, pages 683-688, Numerical Recipies in C, 2nd Edition,
Press, Teukolsky, Vettering, and Flannery, 1992.
"This method is the Gradient-expansion algorithm which
combines the best features of the gradient search with
the method of linearizing the fitting function."
Iterations are performed until three consequtive iterations fail
to chang the chi square changes by greater than TOL, or until
ITMAX, but at least ITMIN, iterations have been performed.
The initial guess of the parameter values should be
as close to the actual values as possible or the solution
may not converge.
The function may fail to converge, or it can encounter
a singular matrix. If this happens, the routine will fail
with the Numerical Recipes error message:
EXAMPLE:
Fit a function of the form:
f(x)=a(0) * exp(a(1)*x) + a(2) + a(3) * sin(x)
Define a lmfit return function:
function myfunct,x,a
;Return a vector appropriate for LMFIT
;The function being fit is of the following form:
; F(x) = A(0) * exp( A(1) * X) + A(2) + A(3) * sin(x)
; dF(x)/dA(0) = exp(A(1)*X)
; dF(x)/dA(1) = A(0)*X*exp(A(1)*X) = bx * X
; dF(x)/dA(2) = 1.0
; dF(x)/dA(3) = sin(x)
bx=A(0)*exp(A(1)*X)
return,[[bx+A(2)+A(3)*sin(x)],[exp(A(1)*X)],[bx*X],[1.0],[sin(x)]]
end
pro run_lmfunct
x=findgen(40)/20. ;Define indep & dep variables.
y=8.8 * exp( -9.9 * X) + 11.11 + 4.9 * sin(x)
sig=0.05 * y
a=[10.0,-7.0,9.0,4.0] ;Initial guess
fita=[1,1,1,1]
ploterr,x,y,sig
yfit=lmfit(x,y,a,MEASURE_ERRORS=sig,FITA=FITA,$
SIGMA=SIGMA,FUNCTION_NAME='myfunct')
oplot,x,yfit
for i=0,3 do print,i,a(i),format='("A (",i1,")= ",F6.2)'
end
MODIFICATION HISTORY:
Written, SVP, RSI, June 1996.
Modified, S. Lett, RSI, Dec 1997
Jan 1998
Feb 1998
Modified: CT, RSI, July 2000: Add MEASURE_ERRORS,
Add double-precision default TOL
[Previous]
[Next]
NAME:
LOADCT
PURPOSE:
Load predefined color tables.
CATEGORY:
Image display.
CALLING SEQUENCE:
LOADCT [, Table]
OPTIONAL INPUTS:
Table: The number of the pre-defined color table to load, from 0
to 15. If this value is omitted, a menu of the available
tables is printed and the user is prompted to enter a table
number.
KEYWORD PARAMETERS:
FILE: If this keyword is set, the file by the given name is used
instead of the file colors1.tbl in the IDL directory. This
allows multiple IDL users to have their own color table file.
The specified file must exist.
GET_NAMES: If this keyword is present AND DEFINED, the names
of the color tables are returned as a string array.
No changes are made to the color table.
NCOLORS = number of colors to use. Use color indices from 0
to the smaller of !D.TABLE_SIZE-1 and NCOLORS-1.
Default = !D.TABLE_SIZE = all available colors.
SILENT: If this keyword is set, the Color Table message is suppressed.
BOTTOM = first color index to use. Use color indices from BOTTOM to
BOTTOM+NCOLORS-1. Default = 0.
OUTPUTS:
No explicit outputs.
CALLS: ***
FILEPATH
CALLED BY:
CW_PALETTE_EDITOR, DIALOG_READ_IMAGE, H5_BROWSER, SLICER3, WRITE_BMP, WRITE_GIF
WRITE_NRIF, WRITE_SRF, XLOADCT, cw_itoperationpreview
COMMON BLOCKS:
COLORS: The IDL color common block.
SIDE EFFECTS:
The color tables of the currently-selected device are modified.
RESTRICTIONS:
Works from the file: $IDL_DIR/resource/colors/colors1.tbl or the file specified
with the FILE keyword.
PROCEDURE:
The file "colors1.tbl" or the user-supplied file is read. If
the currently selected device doesn't have 256 colors, the color
data is interpolated from 256 colors to the number of colors
available.
The colors loaded into the display are saved in the common
block COLORS, as both the current and original color vectors.
Interpolation: If the current device has less than 256 colors,
the color table data is interpolated to cover the number of
colors in the device.
MODIFICATION HISTORY:
Old. For a widgetized version of this routine, see XLOADCT in the IDL
widget library.
DMS, 7/92, Added new color table format providing for more than
16 tables. Now uses file colors1.tbl. Old LOADCT procedure
is now OLD_LOADCT.
ACY, 9/92, Make a pixmap if no windows exist for X windows to
determine properly the number of available colors.
Add FILE keyword.
WSO, 1/95, Updated for new directory structure
AB, 10/3/95, The number of entries in the COLORS common block is
now always !D.TABLE_SIZE instead of NCOLORS + BOTTOM as
before. This better reflects the true state of the device and
works with other color manipulations routines.
DLD, 09/98, Avoid repeating a color table name in the printed list.
[Previous]
[Next]
NAME:
LU_COMPLEX
PURPOSE:
This function solves an N by N complex linear system using
LU decomposition. The result is an N-element complex vector.
Alternatively, this function computes the generalized inverse
of an N by N complex array using LU decomposition. The result
is an N by N complex array.
CATEGORY:
Complex Linear Algebra.
CALLING SEQUENCE:
Result = LU_COMPLEX(A, B)
INPUTS:
A: An N by N array (real or complex).
B: An N-element right-side vector (real or complex).
KEYWORD PARAMETERS:
DOUBLE: If set to a non-zero value, computations are done in
double precision arithmetic.
INVERSE: If set to a non-zero value, the generalized inverse of A
is computed. In this case the input parameter B is ignored.
SPARSE: If set to a non-zero value, the input array is converted
to row-indexed sparse storage format. Computations are
done using the iterative biconjugate gradient method.
This keyword is effective only when solving complex linear
systems. This keyword has no effect when calculating the
generalized inverse.
EXAMPLE:
1) Define a complex array (A) and right-side vector (B).
A = [[complex(1, 0), complex(2,-2), complex(-3,1)], $
[complex(1,-2), complex(2, 2), complex(1, 0)], $
[complex(1, 1), complex(0, 1), complex(1, 5)]]
B = [complex(1, 1), complex(3,-2), complex(1,-2)]
Solve the complex linear system (Az = B) for z.
z = LU_COMPLEX(a, b)
2) Compute the generalized inverse of A.
inv = LU_COMPLEX(a, b, /inverse)
PROCEDURE:
LU_COMPLEX solves the complex linear system Az = b using
LU decomposition. If the SPARSE keyword is set, the coefficient
array is converted to row-indexed sparse storage format and the
system is solved using the iterative biconjugate gradient method.
LU_COMPLEX computes the generalized inverse of the complex
array A using LU decomposition if B is supplied as an arbitrary
scalar value or if the INVERSE keyword is set.
REFERENCE:
Numerical Recipes, The Art of Scientific Computing (Second Edition)
Cambridge University Press
ISBN 0-521-43108-5
MODIFICATION HISTORY:
Written by: GGS, RSI, October 1993
Modified: GGS, RSI, February 1994
Transposing the array prior to calling LU_COMPLEX
is no longer necessary. LU_COMPLEX is now able to
compute the generalized inverse of an N by N complex
array using LU decomposition.
Modified: GGS, RSI, June 1994
Included support for sparse complex arrays using the
Numerical Recipes functions NR_SPRSIN and NR_LINBCG.
Modified: GGS, RSI, Decemberber 1994
Added support for double-precision complex inputs.
Reduced internal memory allocation requirements.
Added INVERSE keyword. New documentation header.
Modified: GGS, RSI, April 1996
Modified keyword checking and use of double precision.
Modified: CT, RSI, February 2001
If /INVERSE then ignore second argument. Allow real A.
Use same code path for single & double precision.