home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / hp48 / 5704 < prev    next >
Encoding:
Internet Message Format  |  1992-11-12  |  4.6 KB

  1. From: charliep@hpcvra.cv.hp.com (Charles Patton)
  2. Date: Thu, 12 Nov 1992 19:42:13 GMT
  3. Subject: Re: Passing Functions as Parameters
  4. Message-ID: <193210001@hpcvra.cv.hp.com>
  5. Organization: Hewlett-Packard Co., Corvallis, OR, USA
  6. Path: sparky!uunet!think.com!sdd.hp.com!hp-cv!hp-pcd!hpcvra!charliep
  7. Newsgroups: comp.sys.hp48
  8. References: <6596@dciem.dciem.dnd.ca>
  9. Lines: 146
  10.  
  11. Jeff Orchard writes:
  12. >>I want to pass a function into a program that uses the integrator.
  13. >>I know how to pass things into local variables, but in order to
  14. >>numerically integrate the function it seems to me that I
  15. >>can't just pass 'F'; I have to pass 'F(X)' (so that I can integrate
  16. >>with respect to X).
  17. >>
  18. >>I would like to be able to put 'F' in level 1 and then execute the
  19. >>program.  I DON'T want to have to put 'F(X)' on the stack... because that
  20. >>would force me to integrate with respect to X.  It would be nice if
  21. >>I could integrate with respect to a local variable.
  22. >>
  23. >>OR... my problems would be solved if I could change this... "F(X)"
  24. >>to this... 'F(X)'
  25. >>
  26. >>Any ideas would be appreciated.  Thanks!
  27. >>
  28. >>Jeff Orchard    jorchard@dretor.dciem.dnd.ca
  29. >>
  30.  
  31. This was exactly the capability provided with the HP28's version
  32. of integration. Fortunately for most people, the '48's version
  33. of integration is allowed within expressions. Unfortunately, function
  34. definitions cannot be directly embedded in expressions. 
  35.  
  36. Given below are work-arounds (for both numeric and symbolic integration)
  37. in the case 1) a function definition is provided or case 2) the name
  38. of a function is provided. They are given as recorded dialog with
  39. a '48 in Kermit server mode (ASCII, translate mode 3). The function
  40. given as an example is x -> x^2. In the numeric case, we bind the
  41. function to a local variable ('F' in the examples) and numerically
  42. integrate F(x)dx. In the symbolic case, we apply the function to
  43. a quoted local variable ('y' in the examples) and integrate the
  44. result with respect to y.
  45.  
  46. remote host \"Case 1: Fcn on stack
  47. 1: "Case 1: Fcn on stack"
  48.  
  49. remote host \\<< \\-> x \'x^2\' \\>>
  50. 2: "Case 1: Fcn on stack"
  51. 1:         \<< \-> x 'x^2' \>>
  52.  
  53. remote host \"Numeric:
  54. 3: "Case 1: Fcn on stack"
  55. 2:         \<< \-> x 'x^2' \>>
  56. 1:         "Numeric:"
  57.  
  58. remote host OVER
  59. 4: "Case 1: Fcn on stack"
  60. 3:         \<< \-> x 'x^2' \>>
  61. 2:         "Numeric:"
  62. 1:         \<< \-> x 'x^2' \>>
  63.  
  64. remote host \\<< \\-> F \\<< \'\\.S(0,3,F(x),x)\' \\->NUM \\>>
  65. 5: "Case 1: Fcn on stack"
  66. 4:         \<< \-> x 'x^2' \>>
  67. 3:         "Numeric:"
  68. 2:         \<< \-> x 'x^2' \>>
  69. 1: \<< \-> F \<< '\.S(0,3,F(x),x)' \->NUM \>> \>>
  70.  
  71. remote host EVAL
  72. 4: "Case 1: Fcn on stack"
  73. 3:         \<< \-> x 'x^2' \>>
  74. 2:         "Numeric:"
  75. 1:                     9
  76.  
  77. remote host \"Symbolic:\"
  78. 5: "Case 1: Fcn on stack"
  79. 4:         \<< \-> x 'x^2' \>>
  80. 3:         "Numeric:"
  81. 2:                     9
  82. 1:       "Symbolic:"
  83.  
  84. remote host 4 PICK
  85. 6: "Case 1: Fcn on stack"
  86. 5:         \<< \-> x 'x^2' \>>
  87. 4:         "Numeric:"
  88. 3:                     9
  89. 2:       "Symbolic:"
  90. 1:         \<< \-> x 'x^2' \>>
  91.  
  92. remote host \\<< 0 \\-> F y \\<< 0 \'X\' \'y\' F EVAL \'y\' \\.S \\>> \\>>
  93. 7: "Case 1: Fcn on stack"
  94. 6:         \<< \-> x 'x^2' \>>
  95. 5:         "Numeric:"
  96. 4:                     9
  97. 3:       "Symbolic:"
  98. 2:         \<< \-> x 'x^2' \>>
  99. 1: \<< 0 \-> F y \<< 0 'X' 'y' F EVAL 'y' \.S \>> \>>
  100.  
  101. remote host EVAL
  102. 6: "Case 1: Fcn on stack"
  103. 5:         \<< \-> x 'x^2' \>>
  104. 4:         "Numeric:"
  105. 3:                     9
  106. 2:       "Symbolic:"
  107. 1: 'y^(2+1)/((2+1)*\.dy(y))|(y=X)-(y^(2+1)/((2+1)*\.dy(y))|(y=0))'
  108.  
  109. remote host EVAL
  110. 6: "Case 1: Fcn on stack"
  111. 5:         \<< \-> x 'x^2' \>>
  112. 4:         "Numeric:"
  113. 3:                     9
  114. 2:       "Symbolic:"
  115. 1:               'X^3/3'
  116.  
  117. remote host \"Case 2: Name on stack\"
  118. 7: "Case 1: Fcn on stack"
  119. 6:         \<< \-> x 'x^2' \>>
  120. 5:         "Numeric:"
  121. 4:                     9
  122. 3:       "Symbolic:"
  123. 2:               'X^3/3'
  124. 1: "Case 2: Name on stack"
  125.  
  126. remote host 6 PICK \'G\' STO \'G\'
  127. 8: "Case 1: Fcn on stack"
  128. 7:         \<< \-> x 'x^2' \>>
  129. 6:         "Numeric:"
  130. 5:                     9
  131. 4:       "Symbolic:"
  132. 3:               'X^3/3'
  133. 2: "Case 2: Name on stack"
  134. 1:                   'G'
  135.  
  136. remote host \\<< \\-> F \\<< F RCL \"now revert to case 1\" \\>> \\>>
  137. 9: "Case 1: Fcn on stack"
  138. 8:         \<< \-> x 'x^2' \>>
  139. 7:         "Numeric:"
  140. 6:                     9
  141. 5:       "Symbolicalyy:"
  142. 4:               'X^3/3'
  143. 3: "Case 2: Name on stack"
  144. 2:                   'G'
  145. 1: \<< \-> F \<< F RCL "now revert to case 1" \>> \>>
  146.  
  147. remote host EVAL
  148. 9: "Case 1: Fcn on stack"
  149. 8:         \<< \-> x 'x^2' \>>
  150. 7:         "Numeric:"
  151. 6:                     9
  152. 5:       "Symbolic:"
  153. 4:               'X^3/3'
  154. 3: "Case 2: Name on stack"
  155. 2:         \<< \-> x 'x^2' \>>
  156. 1: "now revert to case 1"
  157.