! Plotting using Procedures,  (PlotNormalCurve.lng)
! Illustrate:
    a) how to generate a chart/plot/graph of a function,
       in this case the Normal density vs. the Student t density,
    b) the wide range of probability distributions available in LINGO,
    c) how to use a procedure or function to record a computation 
       that will be used repeatedly.

! Keywords: Procedures in LINGO, Chart, Graph, Normal distribution, Student t;
PROCEDURE CALCPDF:
! A procedure that calculates the probability density function
  for the Normal and for the Student t distributions;
  YN = @PNORMPDF( MU, SIGMA, X);
  YT = @PSTUTPDF( DF, X);
ENDPROCEDURE

CALC:
  @SET( 'TERSEO',2); ! Output level (0:verb, 1:terse, 2:only errors, 3:none);
  DF = 2;  ! Degrees of freedom for the t distribution.
             As DF approaches infinity, the t approaches the Normal;
  MU = 0;  ! Mean of the Normal;
  SIGMA = 1 + 0.5/DF; ! S.D. of a similar Normal;
  @CHARTPCURVE('Normal vs. Student t pdfs',
     'Value of x',  ! Label of X axis;
     'f(x)',        ! Label of Y axis;
     CALCPDF,       !Function to compute point on graph;
     X, -5*SIGMA, 5*SIGMA, ! X axis variable & bounds;
    'Normal, Sigma = '+@FORMAT(SIGMA,'5.1f'), YN,  ! Curve 1;
    'Student t, df = '+@FORMAT(DF,'5.1f'),    YT); ! Curve 2;
ENDCALC