home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / utility / sm22a.zip / SYMBMATH.H14 < prev    next >
Text File  |  1993-04-21  |  9KB  |  288 lines

  1.             8. Packages
  2.     A package is a SymbMath program file for special use.
  3.     In order to expand the special ability of SymbMath, some 
  4. packages should be included in the user program by
  5.         include('filename')
  6.     The filename is any MS-DOS filename.
  7.     It is recommended that the filename is the same as the function 
  8. name in the program file, and the extension of the filename is .sm in 
  9. order to remember easily the name of the package. e.g. inte.sm is the 
  10. filename of the integral package as the name of integral function is 
  11. inte().
  12.     After including the package, users can call the functions in 
  13. the package from their program.
  14.     The include command must be in a single line anywhere.
  15.     Many packages can be included at a time, however, all names of 
  16. the variables are public and name conflicts must be avoided. 
  17.     Alternately, a part of the package file rather than the whole
  18. package file can be copied into the Edit window by pressing <F7> 
  19. (external copy) in order to save memory space.
  20.     There are many packages. The following are some of them.
  21.  
  22.         Table 8.1      Packages
  23. ------------------------------------------------------------------------
  24. File Name               Package Function
  25.  
  26. init.sm                 initial package when running the program in 
  27.             the Edit window. It contains switches on the 
  28.             default status.
  29. plot.sm            plotting functions.
  30. listplot.sm        plotting a list of data.
  31. d.sm                    derivatives.
  32. inte.sm                 integrals.
  33.  
  34. --------------- shareware version only has above packages --------------
  35.  
  36. units.sm                an units conversion.
  37. trig.sm                 reduction of trig functions.
  38. hyperbol.sm             reduction of hyerbolic functions.
  39. dt.sm                   total derivatives.
  40. NInte.sm                numeric integration.
  41. NSolve.sm               numeric solver of equation.
  42. ODE.sm            ordinary differential equation.
  43. gamma.sm                gamma function.
  44. ei.sm            exponential integral function.
  45. series.sm        Taylor series.
  46. sum.sm            symbolic sum.
  47. InfSum.sm        infinite sum.
  48. chemical.sm             the atomic weight of chemical elements.
  49. inorgani.sm             inorganic chemical reactions.
  50. -----------------------------------------------------------------------
  51.     
  52.  
  53.         8.1 Initial Package
  54. ---------------------------------------------------------------------
  55. #    The initial package init.sm
  56. output=off
  57. numerical=off
  58. expand=off
  59. sum(y_,x_,a_,b_) := sum(y,x,a,b,1)
  60. prod(y_,x_,a_,b_) := prod(y,x,a,b,1)
  61. list(y_,x_,a_,b_) := list(y,x,a,b,1)
  62. table(y_,x_,a_,b_) := table(y,x,a,b,1)
  63. table(y_,x_) := table(y,x,-5,5,1)
  64. degree=pi/180
  65. 0!=1
  66. inf!=inf
  67. sgn(0)=0
  68. sgn(zero)=1
  69. sgn(e)=1
  70. sgn(pi)=1
  71. sgn(inf)=1
  72. abs(zero)=zero
  73. abs(e)=e
  74. abs(pi)=pi
  75. abs(inf)=inf
  76. ln(0)=-inf
  77. ln(inf)=inf
  78.  include('plot.sm')
  79. # include('d.sm')
  80. block(output=basic,null)
  81. end
  82. ---------------------------------------------------------------------
  83.  
  84.     When running the program in the Edit window, SymbMath 
  85. automatically first includes (or runs) the initial package 'init.sm'. 
  86. The commands in the 'init.sm' package seems the SymbMath system 
  87. commands. You can include other packages (e.g. d.sm) in the initial 
  88. package 'init.sm' so the derivatives table in the package 'd.sm' seems 
  89. to be in SymbMath system. Doing this is by changing the comment 
  90. statement in the last third line 
  91.         # include('d.sm')
  92. to include statement
  93.         include('d.sm')
  94.  
  95.  
  96.         8.2 Derivative Package
  97.        The package 'd.sm' is extention of the d(f(x),x) function.
  98.  
  99.         8.3 Total Derivative Package
  100.        The package 'dt.sm' is for the total derivative function 
  101. dt(f(x,y),x,y).
  102.     Example:
  103.     Input:
  104. include('dt.sm')
  105. dt(x*y, x, y)    
  106. end
  107.     Output:
  108. y*d(x) + x*d(y)
  109.     
  110.         8.4 Integral Package
  111.        The package 'inte.sm' is the extention of the function inte(f(x),x).
  112.  
  113.         8.5 Numeric Integration Package
  114.     The function
  115.         ninte(y, x from x0 to x1)
  116. in the package 'NInte.sm' can do numerical integration.
  117.     Example 8.5.1. Compare numerical and symbolic integrations 
  118. for 4/(x^2+1) with respect to x taken from x=0 to x=1.
  119.     Input:
  120. include('NInte.sm')
  121. ninte(4/(x^2+1), x from 0 to 1)
  122. num(inte(4/(x^2+1), x from 0 to 1))
  123. end
  124.     Output:
  125. done
  126. 3.1415
  127. 3.1416
  128.         
  129.         8.6 Numerical Solving
  130.     The function 
  131.         nsolve( f(x) === x, x, x0) 
  132. in the package 'NSolve.sm' can numerically solve an algebraic equation 
  133. with an initial value x0.
  134.     Example 8.6.1. solve the equation sin(x) === 1 with x0=1.
  135.     Input:
  136. include('NSolve.sm')
  137. nsolve( sin(x) === 1, x, 1)
  138. end
  139.     Output:
  140. done
  141. 1.5364150214
  142.  
  143.         8.7 Series Package
  144.     The series package 'Series.sm' has a function series() for the 
  145. Taylor series at x=0:
  146.     You can call the function
  147.         series(f(x), x, order)
  148.         series(f(x), x)
  149. to find the Taylor series. The arguement (order) is optional and 
  150. defaults to 6.
  151.     Example 8.7.1. Find the power series expansion for cos(x)
  152. about the point x=0 to order x^4.
  153.     Input:
  154. include('series.sm')
  155. series(cos(x), x, 4)
  156. end
  157.     Output:
  158. 1 - 1/2*x^2 + 1/24*x^4
  159.  
  160.         8.8 Infinite Sum Package
  161.     The infinite sum package 'InfSum.sm' has a function
  162.         infsum(f(x),x)    
  163. to find the infinite sum, sum(f(x), x from 0 to inf).
  164.     Example:
  165.     Input:
  166. include('infsum.sm')
  167. infsum(1/n!, n)
  168. end
  169.     Output:
  170. e
  171.             
  172.         8.9 Chemical Calculation Package
  173.     SymbMath recognizes 100 symbols of chemical elements and 
  174. converts them into their atomic weights after the chemical package of
  175. 'Chemical.sm' is included.
  176.  
  177.     Example 8.9.1. Calculate the weight percentage of the
  178. element C in the molecule CH4.
  179.     Input:
  180. include('chemical.sm')
  181. numerical=on
  182. C/(C+H*4)*100*%
  183. end
  184.     Output:
  185. done
  186. numerical = on
  187. 74.868 %
  188.  
  189.     Example 8.9.2. Calculate the molar concentration of CuO when
  190. 3 gram of CuO is in 0.5 litre of a solution.
  191.     Input:
  192. include('chemical.sm')
  193. numerical=on
  194. g=1/(Cu+O)*mol
  195. 3*g/(0.5*l)
  196. end
  197.     Output:
  198. 0.07543*mol/l
  199.  
  200.         8.10 Chemical Reactions Package
  201.     SymbMath can provide the answers for inorganic chemical 
  202. reactions after the inorganic reaction package "Inorgani.sm" is included.
  203.  
  204.     Example 8.10.1.  What are the products when the reactors are
  205. HCl + NaOH ?
  206.     Input:
  207. include('inorgani.sm')
  208. HCl+NaOH
  209. end
  210.     Output:
  211. H2O + NaCl
  212.  
  213.  
  214.         8.11 Plot Function Package
  215. ---------------------------------------------------------------------
  216. # The plot function package plot.sm
  217. # to plot a function.
  218. # plot(x^2, x)        # plot the function of x^2
  219. # plot(x^2, x,-6,6)    # plot the function of x^2 from x=-6 to x=6
  220. # end
  221.  
  222. output=off
  223. plot(y_,x_,x1_,x2_,dx_) := block(openfile('symbmath.out'),
  224.     table(y,x,x1,x2,dx),
  225.     closefile('symbmath.out'),
  226.     system(plotdata))
  227. plot(y_,x_,x1_,x2_) := plot(y,x,x1,x2,(x2-x1)*0.5)
  228. plot(y_,x_) := plot(y,x,-5,5,0.5)
  229. output=on
  230. end
  231. ----------------------------------------------------------------------
  232.  
  233.     If SymbMath is interfaced with the software PlotData, SymbMath 
  234. produces the data table of functions, and PlotData plots from the 
  235. table. So SymbMath seems to plot the function. This interface can be 
  236. used to solve equations graphically.
  237.     In the plot package 'plot.sm' the funcion
  238.         plot(y, x, x1, x2, dx)
  239. first open a file 'SymbMath.Out' for writing, then write the data table 
  240. of the function y into the file 'SymbMath.out', then close the file, 
  241. and finally automatically call the software PlotData to plot. After it 
  242. exits from PlotData, it automatically return to SymbMath.
  243.     The functions
  244.         plot(y, x)
  245.         plot(y, x from xmin to xmax)
  246. call the function plot(y,x,x1,x2,dx)
  247.     e.g. plot x^2.
  248.     Input:
  249. plot(x^2, x)
  250. end
  251.  
  252. in the software PlotData, just select the option to read the file 
  253. 'SymbMath.out' and to plot. PlotData read the data in the SymbMath 
  254. format without any modification (and in many data format). 
  255.     In PlotData, 
  256. in the main menu:
  257. 1 <Enter>
  258. in the read menu:
  259. 1 <Enter>
  260. <Enter>
  261. in the main menu:
  262. 2 <Enter>
  263. in the graph menu:
  264. 1 <Enter>
  265.  
  266. where <Enter> is the <Enter> key.
  267. Refer to PlotData for detail.
  268.     Note that if your monitor is Hercules, you must load the 
  269. MSHERC.COM program as a TRS program before you run PlotData. 
  270. Otherwise you will get Error when you plot.
  271.  
  272.         8.12 List Plot Package
  273. ----------------------------------------------------------------------
  274. # the list plot package 'listplot.sm'
  275. # to plot a list of data.
  276. # listplot([1,2,3,4,5,4,3,2,1])
  277. # end
  278.  
  279. output=off
  280. listplot(y_) := if(islist(y), block(yy=y, length=length(yy),
  281.     openfile('symbmath.out'),
  282.     table(yy[xx],xx,1,length),
  283.     closefile('symbmath.out'),
  284.     system(plotdata) ))
  285. output=on
  286. end
  287. ---------------------------------------------------------------------
  288.