home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / misc / math / 1dexplor.cpt / FunctionTemplate.p < prev    next >
Encoding:
Text File  |  1992-05-25  |  3.5 KB  |  123 lines

  1. UNIT ExternalFunction;
  2. {Note: Creating plug-in functions for the non-FPU version is possible, but not that helpful}
  3. {The overhead of SANE outweighs the overhead of the function interpreter, whereas with}
  4. {the FPU, the overhead of the function interpreter slows the application down considerably }
  5. {from optimum speed.}
  6.  
  7. {For other language platforms: Your code must be stored un a file of type 'Plug' with creator}
  8. {'GrFP'.  The actual code must be stored in a resource of type 'Func'.  You must use the }
  9. {FPU,  since the program uses the FPU extended format.  Your code must accept a message }
  10. {integer and a variable info pointer.  It should not ever allocate memory for the pointer. }
  11. {It should return an extended type (96 bits) as it's result.  The messages are fairly self }
  12. {explanatory. Variables are passed each time in the Info pointer, and the numbers are stored as }
  13. {pointers to extended type.  X is the main variable and P is a variable parameter (used, for}
  14. {example in the bifurcation plot) .  For operations requiring a number of iterations, an integer N }
  15. {is passed}
  16.  
  17. INTERFACE
  18.  
  19.     CONST
  20.         GetName = -1;
  21. {Return the nameof the function in Info^ as you want it to appear in the menu}
  22. {Assume the space has been allocated}
  23.         InitFunc = 0;
  24. {Return the default parameters, bounds  in the form of Initrec.)}
  25. {Assume the space has been allocated}
  26.         ReturnFunc = 1;
  27. {return the flat out first iterate of your function}
  28.         ReturnNthX = 2;
  29. {return the Nth iterate with respect to x of your function}
  30. {YOU MUST RESTORE the value of X^ to its original value}
  31.         ReturnNthP = 3;
  32. {Not used}
  33.         Return1DerivX = 4;
  34. {return the real first derivative of x}
  35.         Return2DerivX = 5;{Not used - maybe in the future}
  36.         Return3DerivX = 6;{Not used}
  37.         return4DerivX = 7;{Not used}
  38.         Return1DerivP = 8;{Not used}
  39.         Return2DerivP = 9;{Not used}
  40.         Return3DerivP = 10;{Not used}
  41.         return4DerivP = 11;{Not used}
  42.         ReturnIntegralX = 12;{Not used}
  43.         ReturnIntegralP = 13;{Not used}
  44.  
  45.     TYPE
  46.         NumberPtr = ^NumberType;
  47.         NumberType = extended;
  48.  
  49.         NamePtr = ^Str255;
  50.  
  51.         InitPtr = ^InitRec;
  52.         InitRec = RECORD
  53.                 Xmin, XMax, FXmin, FXmax, PMin, PMax: NumberType;
  54.                 InitialX, InitialX0, InitialP: NumberType;
  55.             END;
  56.  
  57.         DoFuncPtr = ^DoFuncRec;
  58.         DoFuncRec = RECORD
  59.                 X, P: NumberPtr;
  60.                 N: Integer;
  61.             END;
  62.  
  63.  
  64.     FUNCTION Main (message: integer; VAR Info: ptr): NumberType;
  65.  
  66. IMPLEMENTATION
  67.  
  68.     FUNCTION Main (message: integer; VAR Info: ptr): NumberType;
  69.         VAR
  70.             result, XHold: extended;
  71.             i: integer;
  72.     BEGIN
  73.         WITH DoFuncPtr(Info)^ DO
  74.             CASE message OF
  75.  
  76.                 GetName: 
  77.                     NamePtr(info)^ := 'p*x*(1-x)';
  78.  
  79.  
  80.                 ReturnFunc:
  81. {*****************INSERT FUNCTION HERE*********************}
  82.                     result := p^ * x^ * (1 - x^);
  83. {******************************************************}
  84.  
  85.                 ReturnNthX: 
  86.                     BEGIN
  87.                         XHold := X^;
  88.                         FOR I := 1 TO N DO
  89. {*****************INSERT FUNCTION HERE*********************}
  90.                             X^ := p^ * x^ * (1 - x^);
  91. {******************************************************}
  92.                         Result := X^;
  93.                         X^ := XHold;
  94.                     END;
  95.  
  96.                 Return1DerivX:
  97. {*****************INSERT DERIVATIVE HERE*********************}
  98.                     result := p^ - 2 * p^ * x^;
  99. {******************************************************}
  100.  
  101.                 InitFunc: 
  102.                     WITH initptr(Info)^ DO
  103.                         BEGIN
  104.                             XMin := 0;
  105.                             XMax := 1;
  106.                             FXMin := 0;
  107.                             FXMax := 1;
  108.                             PMin := 0;
  109.                             PMax := 4;
  110.                             InitialX := 0.5;
  111.                             InitialX0 := 0.5;
  112.                             initialP := 3.839;
  113.                             result := 0;
  114.                         END;
  115.  
  116.                 OTHERWISE
  117.                     info := NIL;
  118.             END;
  119.  
  120.         Main := Result;
  121.     END;
  122.  
  123. END.