Ignore:
Timestamp:
07/06/06 16:10:25 (18 years ago)
Author:
pinsard
Message:

improvements of Interpolation/*.pro header

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SRC/Interpolation/spl_incr.pro

    r121 r125  
    1212; in a way that interpolated values are also monotonically increasing. 
    1313; 
    14 ; @param x1 {in}{required}   
    15 ; An n-element (at least 2) input vector that specifies the tabulate points in  
     14; @param x1 {in}{required} 
     15; An n-element (at least 2) input vector that specifies the tabulate points in 
    1616; a strict ascending order. 
    1717; 
    18 ; @param y1 {in}{required}   
     18; @param y1 {in}{required} 
    1919; f(x) = y. An n-element input vector that specifies the values 
    2020;    of the tabulated function F(Xi) corresponding to Xi. As f is 
     
    2222;    monotonically increasing. y can have equal consecutive values. 
    2323; 
    24 ; @param x2 {in}{required}   
     24; @param x2 {in}{required} 
    2525; The input values for which the interpolated values are 
    26 ; desired. Its values must be strictly monotonically increasing.  
     26; desired. Its values must be strictly monotonically increasing. 
    2727; 
    2828; @param der2 
    29 ; @param x  
    30 ; 
    31 ; @returns  
     29; @param x 
     30; 
     31; @returns 
    3232; 
    3333;    y2: f(x2) = y2. Double precision array 
     
    3737;   values (amplitude smaller than 1.e-6)... 
    3838; 
    39 ; @examples  
     39; @examples 
    4040; 
    4141; IDL> n = 100L 
    42 ; IDL> x = (dindgen(n))^2  
     42; IDL> x = (dindgen(n))^2 
    4343; IDL> y = abs(randomn(0, n)) 
    4444; IDL> y[n/2:n/2+1] = 0. 
     
    5353; IDL> oplot, x2, y2, color = 100 
    5454; IDL> c = y2[1:n2-1] - y2[0:n2-2] 
    55 ; IDL> print, min(c) LT 0  
     55; IDL> print, min(c) LT 0 
    5656; IDL> print, min(c, max = ma), ma 
    5757; IDL> splot,c,xstyle=1,ystyle=1, yrange=[-.01,.05], ysurx=.25, petit = [1, 2, 2], /noerase 
     
    8787 
    8888;+ 
    89 ; @param x1 {in}{required}   
    90 ; An n-element (at least 2) input vector that specifies the tabulate points in  
     89; @param x1 {in}{required} 
     90; An n-element (at least 2) input vector that specifies the tabulate points in 
    9191; a strict ascending order. 
    9292; 
    93 ; @param y1 {in}{required}   
     93; @param y1 {in}{required} 
    9494; f(x) = y. An n-element input vector that specifies the values 
    9595;    of the tabulated function F(Xi) corresponding to Xi. As f is 
     
    9797;    monotonically increasing. y can have equal consecutive values. 
    9898; 
    99 ; @param x2 {in}{required}   
     99; @param x2 {in}{required} 
    100100; The input values for which the interpolated values are 
    101 ; desired. Its values must be strictly monotonically increasing.  
     101; desired. Its values must be strictly monotonically increasing. 
    102102; 
    103103; @param der2 
    104 ; @param x  
     104; @param x 
    105105; 
    106106;- 
     
    134134; @keyword YPN_1 The first derivative of the interpolating function at the 
    135135;    point Xn-1. If YPN_1 is omitted, the second derivative at the 
    136 ;    boundary is set to zero, resulting in a "natural spline."  
     136;    boundary is set to zero, resulting in a "natural spline." 
    137137;- 
    138138FUNCTION spl_incr, x, y, x2, YP0 = yp0, YPN_1 = ypn_1 
     
    148148  nx2 = n_elements(x2) 
    149149; x must have at least 2 elements 
    150   IF nx LT 2 THEN stop  
     150  IF nx LT 2 THEN stop 
    151151; y must have the same number of elements than x 
    152152  IF nx NE ny THEN stop 
    153153; x be monotonically increasing 
    154   IF min(x[1:nx-1]-x[0:nx-2]) LE 0 THEN stop  
     154  IF min(x[1:nx-1]-x[0:nx-2]) LE 0 THEN stop 
    155155; x2 be monotonically increasing 
    156156  IF N_ELEMENTS(X2) GE 2 THEN $ 
    157   IF min(x2[1:nx2-1]-x2[0:nx2-2])  LE 0 THEN stop  
     157  IF min(x2[1:nx2-1]-x2[0:nx2-2])  LE 0 THEN stop 
    158158; y be monotonically increasing 
    159   IF min(y[1:ny-1]-y[0:ny-2]) LT 0 THEN stop  
     159  IF min(y[1:ny-1]-y[0:ny-2]) LT 0 THEN stop 
    160160;--------------------------------- 
    161161; first check: check if two consecutive values are equal 
     
    172172    xinx2_1 = value_locate(x2, x[bad+1]) 
    173173; 
    174 ; left side ... if there is x2 values smaller that x[bad[0]].  
     174; left side ... if there is x2 values smaller that x[bad[0]]. 
    175175; we force ypn_1 = 0.0d 
    176176    IF xinx2[0] NE -1 THEN BEGIN 
     
    178178        IF xinx2[0] NE 0 THEN stop 
    179179        y2[0] = y[0] 
    180       ENDIF ELSE BEGIN  
     180      ENDIF ELSE BEGIN 
    181181        y2[0:xinx2[0]] $ 
    182182          = spl_incr(x[0:bad[0]], y[0:bad[0]], x2[0:xinx2[0]] $ 
    183183                     , yp0 = yp0, ypn_1 = 0.0d) 
    184       ENDELSE  
    185     ENDIF  
     184      ENDELSE 
     185    ENDIF 
    186186; flat section 
    187187    IF xinx2_1[0] NE -1 THEN $ 
     
    206206        ENDFOR 
    207207      ENDIF 
    208 ; right side ... if there is x2 values larger that x[bad[cntbad-1]+1].  
     208; right side ... if there is x2 values larger that x[bad[cntbad-1]+1]. 
    209209; we force yp0 = 0.0d 
    210210      IF xinx2_1[cntbad-1] NE nx2-1 THEN $ 
     
    237237; 
    238238; we define the new values of the keyword ypn_1: 
    239 ; if the first derivative of the last value of x is negative  
     239; if the first derivative of the last value of x is negative 
    240240; we define the new values of the keyword ypn_1 to 0.0d0 
    241     IF bad[cntbad-1] EQ nx-1 THEN BEGIN  
     241    IF bad[cntbad-1] EQ nx-1 THEN BEGIN 
    242242      ypn_1new = 0.0d 
    243243; we remove this case from the list 
     
    248248; 
    249249; we define the new values of the keyword yp0: 
    250 ; if the first derivative of the first value of x is negative  
     250; if the first derivative of the first value of x is negative 
    251251; we define the new values of the keyword yp0 to 0.0 
    252252    IF bad[0] EQ 0 THEN BEGIN 
     
    265265; else: there is still cases with negative derivative ... 
    266266; we will cut spl_incr in n spl_incr and specify yp0, ypn_1 
    267 ; for each of this n spl_incr   
     267; for each of this n spl_incr 
    268268    ENDIF ELSE BEGIN 
    269269; define xinx2: see help of value_locate 
     
    273273      xinx2 = value_locate(x2, x[bad]) 
    274274      y2 = dblarr(nx2) 
    275 ; left side ... if there is x2 values smaller that x[bad[0]].  
     275; left side ... if there is x2 values smaller that x[bad[0]]. 
    276276; we force ypn_1 = 0.0d 
    277277      IF xinx2[0] NE -1 THEN $ 
     
    280280                        , yp0 = yp0new, ypn_1 = 0.0d) 
    281281; middle pieces ... if cntbad gt 1 then we have to cut spl_incr in 
    282 ; more than 2 pieces -> we have middle pieces for which  
     282; more than 2 pieces -> we have middle pieces for which 
    283283; we force yp0 = 0.0d and ypn_1 = 0.0d 
    284284      IF cntbad GT 1 THEN BEGIN 
     
    295295        ENDFOR 
    296296      ENDIF 
    297 ; right side ... if there is x2 values larger that x[bad[cntbad-1]].  
     297; right side ... if there is x2 values larger that x[bad[cntbad-1]]. 
    298298; we force yp0 = 0.0d 
    299299      IF xinx2[cntbad-1] NE nx2-1 THEN $ 
     
    302302                        , x2[xinx2[cntbad-1]+1:nx2-1] $ 
    303303                        , yp0 = 0.0d, ypn_1 = ypn_1new) 
    304     ENDELSE  
     304    ENDELSE 
    305305; we return the checked and corrected value of yfrst 
    306306;       FOR i = 0, nx-1 DO BEGIN 
    307307;         same = where(abs(x2- x[i]) LT 1.e-10, cnt) 
    308 ; ;        IF cnt NE 0 THEN y2[same] = y[i]  
     308; ;        IF cnt NE 0 THEN y2[same] = y[i] 
    309309;       ENDFOR 
    310310    RETURN, y2 
     
    313313; we can be in this part of the code only if: 
    314314;  (1) spl_incr is called by itself 
    315 ;  (2) none are the first derivative in x are negative (because they have been  
    316 ;      checked and corrected by the previous call to spl_incr, see above)   
     315;  (2) none are the first derivative in x are negative (because they have been 
     316;      checked and corrected by the previous call to spl_incr, see above) 
    317317;--------------------------------- 
    318318; third check: we have to make sure that the first derivative cannot 
     
    321321; 
    322322; first we compute the first derivative, next we correct the values 
    323 ; where we know that the first derivative can be negative.  
     323; where we know that the first derivative can be negative. 
    324324; 
    325325  y2 = spl_interp(x, y, yscd, x2, /double) 
     
    330330; y''= 6a*X   + 2b 
    331331; if we take X = x[i+1]-x[i] then 
    332 ;    d = y[i]; c = y'[i]; b = 0.5 * y''[i],  
     332;    d = y[i]; c = y'[i]; b = 0.5 * y''[i], 
    333333;    a = 1/6 * (y''[i+1]-y''[i])/(x[i+1]-x[i]) 
    334 ;  
     334; 
    335335; y'[i] and y'[i+1] are positive so y' can be negative 
    336 ; between x[i] and x[i+1] only if  
     336; between x[i] and x[i+1] only if 
    337337;   1) a > 0 
    338338;            ==> y''[i+1] > y''[i] 
    339 ;   2) y' reach its minimum value between  x[i] and x[i+1]  
    340 ;      -> 0 < - b/(3a) < x[i+1]-x[i]  
     339;   2) y' reach its minimum value between  x[i] and x[i+1] 
     340;      -> 0 < - b/(3a) < x[i+1]-x[i] 
    341341;            ==> y''[i+1] > 0 > y''[i] 
    342342; 
     
    412412; in those cases, the first derivative has 2 zero between 
    413413; x[bad[ib]] and x[bad[ib]+1]. We look for the minimum value of the 
    414 ; first derivative that correspond to the inflection point of y               
     414; first derivative that correspond to the inflection point of y 
    415415              xinfl = -bbb[ib]/(3.0d*aaa[ib]) 
    416416; we compute the y value for xinfl 
    417417              yinfl = aaa[ib]*xinfl*xinfl*xinfl + bbb[ib]*xinfl*xinfl $ 
    418418                + ccc[ib]*xinfl + ddd[ib] 
    419 ;                 
     419; 
    420420              CASE 1 OF 
    421421; if y[xinfl] smaller than y[bad[ib]] then we conserve y2 until 
     
    450450                                     , yifrst[bad[ib]+1] $ 
    451451                                     , x2[xinx2_3+1:xinx2_2[ib]]) 
    452                   ENDIF                 
     452                  ENDIF 
    453453                END 
    454454; if y[xinfl] bigger than y[bad[ib]+1] then we conserve y2 from 
     
    480480                                    , yifrst[bad[ib]] $ 
    481481                                    , x2[xinx2_1[ib]+1:xinx2_3]) 
    482                   ENDIF                 
     482                  ENDIF 
    483483                END 
    484484                ELSE:BEGIN 
     
    496496                                    , yifrst[bad[ib]] $ 
    497497                                    , x2[xinx2_1[ib]+1:xinx2_3]) 
    498                      
    499                   ENDIF                 
     498 
     499                  ENDIF 
    500500                  IF xinx2_2[ib] GE xinx2_3+1 THEN BEGIN 
    501501                    y2[xinx2_3+1:xinx2_2[ib]] $ 
     
    504504                                     , yifrst[bad[ib]+1] $ 
    505505                                     , x2[xinx2_3+1:xinx2_2[ib]]) 
    506                   ENDIF                 
     506                  ENDIF 
    507507                END 
    508508              ENDCASE 
    509509 
    510             END  
     510            END 
    511511          ENDCASE 
    512512        ENDIF 
Note: See TracChangeset for help on using the changeset viewer.