;+ ; NAME: ; LEGPOLY ; ; PURPOSE: ; Evaluate a sum of legendre polynomial functions of a variable. ; ; CATEGORY: ; C1 - Operations on polynomials. ; ; CALLING SEQUENCE: ; Result = LEGPOLY(X,C) ; ; INPUTS: ; X: The variable. This value can be a scalar, vector or array. ; ; C: The vector of legendre polynomial coefficients. The degree of ; of the polynomial is N_ELEMENTS(C) - 1. ; ; OUTPUTS: ; LEGPOLY returns a result equal to: ; C[0] + c[1] * LEGENDRE(X,1) + c[2]*LEGENDRE(x,2) + ... ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; None. ; ; RESTRICTIONS: ; Designed for X between -1 and 1. ; ; PROCEDURE: ; Straightforward. ; ; MODIFICATION HISTORY: ; LAY, Written, Dec 2010 ; ; BASED ON RSI FUNCTION POLY ; $Id: //depot/idl/IDL_70/idldir/lib/poly.pro#2 $ ; ; Copyright (c) 1983-2008, ITT Visual Information Solutions. All ; rights reserved. Unauthorized reproduction is prohibited. ; DMS, Written, January, 1983. ; CT, RSI, Nov 2004: Special case for zero-order polynomial. ; Be sure to still return an array. ;- FUNCTION LEGPOLY,X,C compile_opt idl2 on_error,2 ;Return to caller if an error occurs N = N_ELEMENTS(C)-1 ;Find degree of polynomial ; Special case for N=0. Be sure to return a result of the ; same type and array dimensions as X. if (n eq 0) then $ return, x*0 + c[0] leg_last = x*0 + 1. leg = x Y = c[0] + c[1] * x for l=2,n do begin y += legendre(x,l) end return,y end