Previous Page | Next Page

The FCMP Procedure

Example 4: Using GTL with User-Defined Functions


Procedure features:

PROC FCMP functions

OSCILLATE

OSCILLATEBOUND

Other procedures

PROC TEMPLATE

PROC SGRENDER


The following example shows how to define functions that define new curve types (oscillate and oscillateBound). These functions can be used in a GTL EVAL function to compute new columns that are presented with a seriesplot and bandplot.


Program

 Note about code
proc fcmp outlib=sasuser.funcs.curves;
   function oscillate(x,amplitude,frequency);
         if amplitude le 0 then amp=1; else amp=amplitude;
	      if frequency le 0 then freq=1; else freq=frequency;
         y=sin(freq*x)*constant("e")**(-amp*x); 
         return (y);
  endsub;
 Note about code
 function oscillateBound(x,amplitude);
       if amplitude le 0 then amp=1; else amp=amplitude;
       y=constant("e")**(-amp*x); 
       return (y);
  endsub;
 run;
 Note about code
 options cmplib=sasuser.funcs;
  
data range;
   do Time=0 to 2 by .01;
   output;
   end;
run;
 Note about code
proc template ;
   define statgraph damping;
   dynamic X AMP FREQ;
   begingraph;
       entrytitle "Damped Harmonic Oscillation";
       layout overlay / yaxisopts=(label="Displacement");
          if (exists(X) and exists(AMP) and exists(FREQ)) 
	            bandplot x=X  limitlower=eval(-oscillateBound(X,AMP)) 
                limitupper=eval(oscillateBound(X,AMP));
                seriesplot x=X y=eval(oscillate(X,AMP,FREQ));
	      endif;
	    endlayout;
   endgraph;
   end;
   run;
 Note about code
 ods html; 
 Note about code
 proc sgrender data=range template=damping;
      dynamic x="Time" amp=10 freq=50 ;
 run;
 Note about code
     ods html close;

Output

[untitled graphic]

Previous Page | Next Page | Top of Page