next up previous contents index
Next: Dealing with data Up: DATA MANIPULATION Previous: Find the root

A simple integration procedure

The following script, integrate.pcm, expects two parameters: the independent and dependent vector names. The following commands generate some data and then call the integrate.pcm procedure, producing the figure on the right. Of course, you could use the INTEGRAL  function instead of this procedure. This is intended only as an example.   

 generate x 0,,3*pi 100
 @integrate x sin(x)

integrate

                    

 ! script integrate.pcm
 !
 ! Assume that you have two vectors X and Y with X(i+1)-X(i) constant
 ! and assume that X and Y have same number of elements.
 ! This file will integrate Y with respect to X and graph the data
 ! and the 'integral'
 SET COLOUR 1
 GRAPH ?1 ?2                    ! plot input data, with axes
 SET LINTYP 3                   ! set line type to dashed line
 SCALAR\DUMMY I
 SET COLOUR 2
 GRAPH\-AXES ?1 RSUM(?2[I],I,1:LEN(?2))*(?1-STEP(?1,1))
 REPLOT                         ! redraw plot on common scale
 SET
  %XLOC 63        ! text x location
  %YLOC 23        ! text y location
   CURSOR -1      ! left justify text
  %TXTHIT 2       ! text height

 TEXT `<c1>sin(x)'              ! draw text string
 SET
  %XLOC 53        ! text x location
  %YLOC 77        ! text y location

 TEXT `<c2><Int>sin(x)dx'
 DEFAULTS                       ! reset program defaults