home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / utility / sm22a.zip / SYMBMATH.DO2 < prev    next >
Text File  |  1993-04-23  |  42KB  |  1,584 lines

  1.     SymbMath 2.2: A Symbolic Calculator with Learning
  2.         (Version 2.2)
  3.  
  4.         by Dr. Weiguang HUANG
  5.     Dept. Analytical Chemsitry, University of New South Wales,
  6.     Kensington, Sydney, NSW 2033, Australia
  7.     Phone: 61-2-697-4643
  8.     Fax:   61-2-662-2835
  9.     E-mail: w.huang@unsw.edu.au
  10.  
  11.         Copyright (C) 1990-1993
  12.         April 15, 1993
  13.  
  14.     This is Part Two of SymbMath manual. The SymbMath manual has
  15. three parts in the files SymbMath.DOC, SymbMath.DO2 and SymbMath.DO3.
  16.     
  17.  
  18.             7. Examples
  19.  
  20.     In the following examples, a line of "Input:" means that 
  21. typing the program in the Editor, then leaving the Editor by <Esc>, 
  22. finally running the program by the command "Run", while a line of 
  23. "Output:" means outputs in the "Output" window. # is a comment 
  24. statement. All examples should be terminated by the end statement,
  25. but the end statement may omit in the output of the following examples.
  26.  
  27.  
  28.         7.1 Simplification and Assumption
  29.  
  30.     SymbMath automatically simplifies the output expression. 
  31. Users can further simplify it by using the built-in variable "last" 
  32. in a singe line again and again until they are happy.
  33.  
  34.     Example 7.1.1. Reduce sqrt(x^2).
  35.     Input:
  36. sqrt(x^2)
  37. end
  38.     Output:
  39. x*sgn(x)
  40. end
  41.  
  42.     A first way to reduce this output expression is to substitute
  43. sgn(x) by 1 if x is positive.
  44.     Input:
  45. sqrt(x^2)
  46. subs(last, sgn(x)=1)
  47. end
  48.     Output:
  49. x*sgn(x)
  50. x
  51. end
  52.     A second way to reduce the output expression is to assume
  53. x>0 before evaluation. On this way, all x is affected. The first 
  54. method is local simplification, but the second method is global
  55. simplification. If users declare the variable x is positive or 
  56. negative by 
  57.  
  58.         assume(x > 0)
  59.         assume(x < 0)
  60.  
  61. the output expression is simpler than that if users do not declare it.
  62.  
  63.     Example 7.1.2. Assume x>0 before reduce sqrt(x^2).
  64.     Input:
  65. assume(x >0)
  66. sqrt(x^2)
  67. end
  68.     Output:
  69. assumed
  70. x
  71. end
  72.  
  73.     Users can assume the variable b is even, odd, integer, real 
  74. number, positive or negative  by
  75.  
  76.         iseven(b) := 1          # assume b is even
  77.         isodd(b) := 1           # assume b is odd
  78.         isinteger(b) := 1       # assume b is integer
  79.         isreal(b) := 1          # assume b is real
  80.         isnumber(b) := 1        # assume b is number
  81.         islist(b) := 1        # assume b is a list
  82.         isfree(y,x) := 1    # assume y is free of x
  83.         sgn(b) := 1             # assume b is positive
  84.         sgn(b) := -1            # assume b is negative
  85.  
  86.     All variables are complex by default.
  87.  
  88.     Example 7.1.3.
  89.     Input:
  90. isreal(b) := 1
  91. sqrt(b^2)
  92. end
  93.     Output:
  94. isreal(b) := 1
  95. abs(b)
  96. end
  97.  
  98.     Example 7.1.4. Set f1=x^2+y^3, then put f1 into sin(f1)+
  99. cos(2*f1) and assign the last output to f2.
  100.     Input:
  101. f1=x^2+y^3
  102. sin(f1)+cos(2*f1)
  103. f2=last
  104. end
  105.     Output:
  106. f1 = x^2 + y^3
  107. sin(x^2 + y^3) + cos(2 (x^2 + y^3))
  108. f2 = sin(x^2 + y^3) + cos(2*(x^2 + y^3))
  109. end
  110.  
  111. where a special word "last" stands for the last output, e.g. here
  112. "last" is sin(x^2+y^3)+cos(2*(x^2+y^3)).
  113.  
  114.  
  115.             7.2 Calculation
  116.  
  117.     SymbMath gives the exact value of calculation when the switch
  118. numerical=off (default), or the approximate value of calculation when 
  119. the switch numerical=on or by the function num().
  120.     SymbMath can manipulate units as well as numbers, be used as 
  121. a symbolic calculator, and do exact computation. The range of real 
  122. numbers is from -infinity to infinity, e.g. ln(-inf), exp(inf+pi*i), 
  123. etc. SymbMath contains many built-in algorithms for performing 
  124. numerical calculations when the switch numerical=on, e.g. ln(-9), i^i, 
  125. (-2.3)^(-3.2), 2^3^4^5^6^7^8^9, etc.
  126.     Warming that SymbMath only gives a principle value if there
  127. are multi-values, except for the function solve().
  128.  
  129.     Example 7.2.1. Find the values of sin(x) when x=pi/2
  130. and x=90 degree.
  131.     Input:
  132. num(sin(pi/2))
  133. num(sin(90*degree))
  134. end
  135.     Output:
  136. 1
  137. 1
  138. end
  139.  
  140.     Example 7.2.2. Set the units converter from the minute to
  141. the second, then calculate numbers with different units.
  142.     Input:
  143. minute=60*second
  144. v=2*meter/second
  145. t=2*minute
  146. d0=10*meter
  147. v*t+d0
  148. end
  149.     Output:
  150. 250 meter
  151.  
  152.     Example 7.2.3
  153.     Input:
  154. 1/2+1/3
  155. end
  156.     Output:
  157. 5/6
  158.         
  159.     Example 7.2.4. Assign sqrt(x) to z, then evaluate z
  160. when x=3 and y=4.
  161.     Input:
  162. z=sqrt(x)
  163. subs(z, x=3)            # evaluate z by substituting x=3
  164. x=4                     # assign 4 to x
  165. z                       # evaluate z 
  166. end
  167.     Output:
  168. z = sqrt(x)
  169. sqrt(3)
  170. x=4
  171. 2
  172.  
  173.     Note that after assignment by x=4, x should be cleared from 
  174. memory by clear(x) before differentiation of the new function. 
  175. Otherwise the values of x still is 4 until new values assigned. If 
  176. evaluating z by the function subs(z, x=3), the variable x is 
  177. automatically cleared after evaluation, i.e. the variable x in subs()
  178. is local variable. This rule applies to other functions. 
  179.  
  180.  
  181.     7.3  Defining Your Own Functions, Procedures and Rules
  182.  
  183.     Anytime you find yourself using the same expression over and 
  184. over, you should turn it into a function.  
  185.     You can define your own functions for evaluation by
  186.  
  187.         f(x_) := x^2
  188.         f(x_) := if(isnumber(x), x^2)
  189.  
  190. On the first definition, when f() is called, it gives x^2, regardless
  191. what x is. On the second definition, when f() is called it gives x^2 
  192. if x is a number, or left unevaluated otherwise.
  193.     You can define the function by the immediate assignment =
  194. or the delayed assignment :=, but you cannot define a conditional
  195. function by the immediate assiment =. It is recommanded to define
  196. the function by the delayed assigment :=.
  197.     The pattern x_ should be only on the left side of the 
  198. assignment.
  199.     Here are some sample function definitions:
  200.            f(x_) := cos(x + pi/3)
  201.            g(x_, y_) := x^2 - y^2
  202. Once defined, functions can be used in expressions or in other 
  203. function definitions:
  204.            y = f(3.2)
  205.            z = g(4.1, -5.3)
  206.  
  207.     Example 7.3.1.
  208. Define a new function f(x)=x^2, then evaluate it.
  209.     Input:
  210. f(x_) := x^2
  211. f(-2)
  212. f(3)
  213. f(a)
  214. end
  215.     Output:
  216. f(x_) := x^2 
  217. 4
  218. 9
  219. a^2
  220.  
  221.     Input:
  222. f(x_) := if(isnumber(x), x^2)
  223. f(-2)
  224. f(3)
  225. f(a)
  226. end
  227.     Output:
  228. f(x_) := if(isnumber(x), x^2)
  229. 4
  230. 9
  231. f(a)
  232.  
  233.     To define a conditional function by
  234.  
  235.         f(x_) := if(x>0, x^2)
  236.         f(x_) := if(x>0, x^2, x)
  237.         f(x_) := x*(x<0) + x^2*(x>0)
  238.  
  239. On the first definition, when f() is called it gives x^2 if x>0, or 
  240. left unevaluated otherwise. On the second definition, when f() is 
  241. called it gives x^2 if x>0, x if x<=0, or left unevaluated otherwise. 
  242. On the last definition, when f() is called, it is evaluated regardless 
  243. what x is.
  244.     You cannot differentiate nor integrate the conditional function
  245. if you define it by if(). But you can do so if you define it by relative
  246. operators (e.g. the last definition).
  247.  
  248.     Input:
  249. f(x_) := if(x>0, x^2)
  250. f(2)
  251. f(a)
  252. end
  253.     Output:
  254. f(x_) := if(x > 0, x^2)
  255. 4
  256. f(-2)
  257. f(a)
  258.  
  259.     Input:
  260. f(x_) := if(x>0, x^2, x)
  261. f(2)
  262. f(-2)
  263. f(a)
  264. end
  265.     Output:
  266. f(x_) := if(x > 0, x^2, x)
  267. 4
  268. 2
  269. f(a)
  270.  
  271.  
  272.     Example 7.3.2. Define a conditional function
  273.  
  274.       / x       if x < 0
  275. f(x) =  0       if x = 0
  276.       \ x^2     if x > 0
  277.  
  278. then evaluate f(-2), f(0), f(3).
  279.     Input:
  280. f(x_) := x*(x<0)+x^2*(x>0)
  281. f(-2)
  282. f(0)
  283. f(3)
  284. f(a)
  285. d(f(t), t=3)
  286. end
  287.     Output:
  288. f(x_) := x*(x < 0) + x^2*(x > 0)
  289. -2
  290. 0
  291. 9
  292. a*(a < 0) + a^2*(a > 0)
  293. 6
  294.  
  295.     To define a recursion function.
  296.     Input:
  297. factorial(n_) := if(n > 1, (n-1)*factorial(n-1))
  298. factorial(1) := 1
  299. end
  300.  
  301.     To define a function as a procedure.
  302.     e.g. define a numerical integration procedure ninte() and 
  303. calculate integral of x^2 from x=1 to x=2 by call ninte().
  304.     Input:
  305. ninte(y_,x_,a_,b_) := block( num( dd=(b-a)/50,
  306.     aa=a+dd,
  307.     bb=b-dd,
  308.     y0=subs(y, x=a),
  309.     yn=subs(y, x=b),
  310.     ff=(sum(y,x,aa,bb,dd)+(y0+yn)/2)*dd),
  311.     ff )
  312. ninte(x^2,x,1,2)
  313. end
  314.  
  315.     Note that all variable within procedure are global. The mult-
  316. statement should be grouped by block(). The block() output only result
  317. of the last statement. The mult-line can be teminated by a comma (,).
  318.  
  319.     You can define transform rules. Defining rules is similar to 
  320. defining functions. In defining functions, all arguments must be simple
  321. variables, but in defining rules, the first argument can be a
  322. complicated expression. In this version of SymbMath the rules only have
  323. two arguments and one pattern.
  324.     e.g. define Laplace transform rules.
  325.     Input:
  326. laplace(sqrt(t_), t_) := sqrt(pi)/2/t^(3/2)
  327. laplace(1/sqrt(t_), t_) := sqrt(pi/t)
  328. laplace(sin(t_), t_) := 1/(t^2+1)
  329. laplace(sin(s), s)
  330. end
  331.     Output:
  332. laplace(sqrt(t_), t_) := sqrt(pi)/2/t^(3/2)
  333. laplace(1/sqrt(t_), t_) := sqrt(pi/t)
  334. laplace(sin(t_), t_) := 1/(t^2+1)
  335. 1/(s^2+1)
  336. end
  337.  
  338.             7.4 Limits
  339.  
  340.     SymbMath finds real or complex limits, and discontinuity
  341. when x approaches to x=x0 by functions 
  342.  
  343.         subs(f, x=x0)
  344.         lim(f, x=x0)
  345.  
  346.     First use subs() to find limits, if the result is undefined
  347. (indeterminate forms, e.g. 0/0, inf/inf, 0*inf, and 0^0), then use 
  348. lim() to try again; if the result is discont, then use the one-side
  349. limit by c+zero or c-zero.
  350.  
  351.     Example 7.4.1. Find limits of types 0/0 and inf/inf.
  352.     Input:
  353. p=(x^2-4)/(2*x-4)
  354. subs(p, x=2)
  355. lim(p, x=2)
  356. subs(p, x=inf)
  357. lim(p, x=inf)
  358. end
  359.     Output:
  360. p = (x^2 - 4)/(2 x - 4)
  361. undefined
  362. 2
  363. undefined
  364. inf
  365.  
  366.     The "discont" (discontinuity) means that the expression has
  367. a discontinuity and only has the one-sided limit value at x=x0. Users 
  368. should use x0+zero or x0-zero to find the one-sided limit. The 
  369. f(x0+zero) or f(x0-zero) is the right-sided limit or left-sided limit 
  370. as approaching x0 from positive (+inf) or negative (-inf) direction, 
  371. respectively, i.e. limit as zero -> 0.
  372.     SymbMath find a left-sided or right-sided limit when x 
  373. approaches to x0 from positive (+inf) or negative (-inf) direction at 
  374. discontinuity by functions
  375.  
  376.         subs(f, x=x0+zero)
  377.         subs(f, x=x0-zero)
  378.         lim(f, x=x0+zero)
  379.         lim(f, x=x0-zero)
  380.  
  381.     Example 7.4.2. Find the left-sided and right-sided limits of
  382. y=exp(1/x), (i.e. when x approaches 0 from positive and negative 
  383. directions).
  384.     Input:
  385. y=exp(1/x)
  386. subs(y, x=0)
  387. subs(y, x=0+zero)
  388. subs(y, x=0-zero)
  389. end
  390.     Output:
  391. y = exp(1/x)
  392. discont
  393. inf
  394. 0
  395.  
  396.     The built-in constants of inf or -inf, zero or -zero, and 
  397. discont or undefined can be used as numbers in calculation of 
  398. expressions or functions.
  399.  
  400.     Example 7.4.3.
  401.     Input:
  402. 1/sgn(0)
  403. 1/sgn(zero)
  404. end
  405.     Output:
  406. discont
  407. 1
  408.  
  409.  
  410.             7.5 Differentiation
  411.  
  412.     SymbMath differentiates an expression expr by functions 
  413.  
  414.         d(expr, x)
  415.         d(expr, x, order)
  416.         d(expr, x=x0)
  417.         d(expr, x=x0, order)
  418.  
  419.     Example 7.5.1. Differentiate x^(x^x).
  420.     Input:
  421. d(x^(x^x), x)
  422. end
  423.     Output:
  424. x^(x^x)*(x^(-1 + x) + x^x*ln(x)*(1 + ln(x)))
  425.  
  426.     Example 7.5.2. Differentiate the expression f=sin(x^2+y^3)+
  427. cos(2*(x^2+y^3)) with respect to x, and with respect to both x and y.
  428.     Input:
  429. f=sin(x^2+y^3)+cos(2*(x^2+y^3))
  430. d(f, x)
  431. d(d(f, x), y)
  432. end
  433.     Output:
  434. f = sin(x^2 + y^3) + cos(2*(x^2 + y^3))
  435. 2*x*cos(x^2 + y^3) - 4*x*sin(2*(x^2 + y^3))
  436. -6*x*y^2*sin(x^2 + y^3) - 12*x*y^2*cos(2*(x^2 + y^3))
  437.  
  438.     To define a derivative.
  439.     Input:
  440. d(si(x_),x_) := sin(x)/x
  441. d(si(t),t)
  442. end
  443.     Output:
  444. d(si(x_),x_) := sin(x)/x
  445. sin(t)/t
  446.  
  447.     Or the package d.sm is included before finding the derviatives.
  448.     Example:
  449.     Input:
  450. include 'd.sm'
  451. d(si(t),t)
  452. end
  453.     Output:
  454. done
  455. sin(t)/t
  456.  
  457.     If SymbMath cannot find some derivatives, you should include 
  458. the package 'd.sm' in your program or in the initial package 'init.sm'.
  459.  
  460.  
  461.             7.6 Integration
  462.  
  463.     SymbMath system itself can find integrals of x^m*e^(x^n),
  464. x^m*e^(-x^n), e^((a*x+b)^n), e^(-(a*x+b)^n), x^m*ln(x)^n, ln(a*x+b)^n,
  465. etc., where m and n are any real number.    
  466.     The package 'inte.sm' and/or 'd.sm' should be included before 
  467. symbolic integration so that it become more powerful on integration. It 
  468. is recommended that to expand the integrand by the function expand() 
  469. and/or by setting the switch expand=on before symbolic integration. 
  470.     If symbolic integration fails, the user can define the simple
  471. integral or derivative, then evaluates the integration again (see 
  472. 7.13 Learning from User).
  473.     If the user wants numerical integration by ninte(), the 
  474. package 'NInte.sm' should be included before doing numerical 
  475. integration (see 8.5 Numeric Integration Package).
  476.  
  477.  
  478.         7.6.1 Indefinite Integration
  479.  
  480.     SymbMath finds indefinite integrals by functions 
  481.  
  482.         inte(expr, x)
  483. Note that the arbitrary constant is not represented.
  484.     
  485.     Example 7.6.1. Find indefinite integrals.
  486.     Input:
  487. inte(sinh(x)*e^sinh(x)*cosh(x), x)
  488. inte(sinh(x)^2*cosh(x), x)
  489. inte(x^1.5*exp(x), x)
  490. end
  491.     Output:
  492. -e^sinh(x) + sinh(x)*e^sinh(x)
  493.  (1/3)*sinh(x)^3
  494. ei(1.5, x)
  495.  
  496.     Example 7.6.2. Find indefinite double integrals.
  497.     Input:
  498. inte(inte(x*y, x), y)
  499. end
  500.     Output:
  501.  (1/4)*x^2*y^2
  502.  
  503.     Example 7.6.3. Find the line integral.
  504.     Input:
  505. x=2*t
  506. y=3*t
  507. z=5*t
  508. u=x+y
  509. v=x-y
  510. w=x+y+z
  511. inte((u*d(u,t)+v*d(v,t)+w*d(w,t), t)
  512. end
  513.     Output:
  514. 63*t^2
  515.  
  516.     Example 7.6.4. Find the integral of sin(x)/x by the mean of
  517. the 'inte.sm' package.
  518.     Input:
  519. include('inte.sm')
  520. inte(sin(x)/x, x)
  521. end
  522.     Output:
  523. done
  524. si(x)
  525.  
  526.     Defining an integral is similar to defining a rule.
  527.     Example 7.6.5
  528.     Input:
  529. inte(sin(x_)/x_, x_) := si(x)
  530. inte(sin(t)/t, t)
  531. end
  532.     Output:
  533. inte(sin(x_)/x_, x_) := si(x)
  534. si(t)
  535.  
  536.         7.6.2 Definite Integration
  537.  
  538.     SymbMath finds definite integrals by functions 
  539.         inte(expr, x, xmin, xmax)
  540.     Example 7.6.6. Find the definite integral of y=exp(1-x) with
  541. respect to x taken from x=0 to x=infinity.
  542.     Input:
  543. inte(exp(1-x), x from 0 to inf)
  544. end
  545.     Output:
  546. e
  547.  
  548.     Example 7.6.7. Discontinuous integration of 1/x^2 and 1/x^3 
  549. with discontinuity at x=0.
  550.     Input:
  551. inte(1/x^2, x from -1 to 2)
  552. inte(1/x^3, x from -1 to 1)
  553. end
  554.     Output:
  555. inf
  556. 0
  557.  
  558.  
  559.             7.7 Equations
  560.             7.7.1 Algebraic Equations
  561.  
  562.     The equations can be operated (e.g. +, -, *, /, ^, expand(), 
  563. diff(), inte()). The operation is done on both sides of the equation, 
  564. as by hand. SymbMath is able to find roots of a polynomial, algebraic 
  565. equations, systems of equations, differential and integral equations.
  566.  
  567.     Example 7.7.1. Solve an equation
  568. sqrt(x+2*k) - sqrt(x-k) === sqrt(k), 
  569. then check the solution by substituting the root into the equation.
  570.     Input:
  571. eq1=(sqrt(x + 2*k) - sqrt(x - k) === sqrt(k))
  572. eq1^2
  573. expand(last)
  574. last-k-2*x
  575. last/(-2)
  576. last^2
  577. expand(last)
  578. last-x^2+2*k^2
  579. last/k
  580. subs(eq1, x=right(last))
  581. end
  582.     Output:
  583. eq1=(sqrt(x + 2*k) - sqrt(x - k) === sqrt(k))
  584. ((2*k + x)^0.5 - ((-k) + x)^0.5)^2 === k
  585. 2*x + k + (-2)*(2*k + x)^0.5*((-k) + x)^0.5 === k
  586. (-2)*(2*k + x)^0.5*((-k) + x)^0.5 === (-2)*x
  587. (2*k + x)^0.5*((-k) + x)^0.5 === x
  588. (2*k + x)*((-k) + x) === x^2
  589. (-2)*k^2 + k*x + x^2 === x^2
  590. k*x === 2*k^2
  591. x === 2*k
  592. k^0.5 === k^0.5
  593.  
  594.     SymbMath can solve many algebraic equations step by step, as 
  595. by hand. This method is useful on teaching, e.g. to show students how 
  596. to solve equations.
  597.     SymbMath has the built-in function 
  598.  
  599.         solve(expr1 === expr2, x)
  600.         solve([expr1 === expr2, expr3 === expr4], [x, y])
  601.  
  602. to solve a polynomial and systems of linear equations on one step.
  603. It is recommended to set the switch expand=on when solve the 
  604. complicated equations. All of the real and complex roots of the 
  605. equation will be found by solve(). The function solve() outputs a 
  606. list of roots when there are multi-roots. Users can get one of roots 
  607. from the list, (see 7.9 List, Array, Vector and Matrices).
  608.     Users can get the left side of the equation by
  609.  
  610.         left(left_side === right_side)
  611.  
  612. or the right side by
  613.  
  614.         right(left_side === right_side)
  615.  
  616.     Example 7.7.2. Solve a+b*x+x^2 === 0, save the root to x.
  617.     Input:
  618. eq1 = (a+b*x+x^2===0)
  619. solve(eq1, x)
  620. x=right(last)
  621. x[1]
  622. x[2]
  623. end
  624.     Output:
  625. eq1 = (a+b*x+x^2 === 0)
  626. x === [-b/2 + sqrt((b/2)^2 - a),  -b/2 - sqrt((b/2)^2 - a)]
  627. x = [-b/2 + sqrt((b/2)^2 - a),  -b/2 - sqrt((b/2)^2 - a)]
  628. -b/2 + sqrt((b/2)^2 - a)
  629. -b/2 - sqrt((b/2)^2 - a)
  630.  
  631.  
  632.     Example 7.7.3. Solve x^3+x^2+x+5 === 2*x+6.
  633.     Input:
  634. num(solve(x^3+x^2+x+5 === 2*x+6, x))
  635. end
  636.     Output:
  637. x === [1, -1, -1]
  638.  
  639.     Function solve() not only solve for a simple variable x
  640. but also for an unknown function, e.g. ln(x).
  641.  
  642.     Example 7.7.4. Solve the equation for ln(x).
  643.     Input:
  644. solve(ln(x)^2+5*ln(x) === -6, ln(x))
  645. exp(last)
  646. end
  647.     Output:
  648. ln(x) === [-2, -3]
  649. x === [exp(-2), exp(-3)]
  650.  
  651.     Example 7.7.5. Rearrange the equations.
  652.     Input:
  653. f = [x+y === 3+a+b, x-y === 1+a-b]
  654. solve(f, [x,y])
  655. solve(f, [a,b])
  656. solve(f, [a,y])
  657. solve(f, [x,b])
  658. end
  659.     Output:
  660. f = [x + y === 3 + a + b, x - y === 1 + a - b]
  661. [x === -1/2*(-4 - 2 a), y === -1/2*(-2 - 2 b)]
  662. [a === -1/2*(4 - 2 x), b === -1/2*(2 - 2 y)]
  663. [b === -1/2*(2 - 2 y), x === -1/2*(-4 - 2 a)]
  664. [a === 1/2*(-4 + 2 x), y === 1/2*(2 + 2 b)]
  665.  
  666.  
  667.  
  668.         7.7.2 Differential Equations
  669.  
  670.     SymbMath can solve the variables separable differential
  671. equations:
  672.         y(x)*d(y(x), x) === f(x)
  673. by integration inte().
  674.     Example: 7.7.2.1
  675.     Input:
  676. y(x)*d(y(x), x) === sin(x)
  677. inte(last, x)
  678. end
  679.     Output:
  680. y(x)*d(y(x), x) === sin(x)
  681. 1/2*y(x)^2 === constant - cos(x)
  682.  
  683.     The function 
  684.  
  685.         dsolve(d(y)/d(x) === f(x,y), y) 
  686.  
  687. can solve the first order variables separable and linear differential 
  688. equations
  689.  
  690.         d(y)/d(x) === h(x) 
  691.         d(y)/d(x) === g(y) 
  692.         d(y)/d(x) === g(y)*x
  693.         d(y)/d(x) === g(x)*y
  694.         d(y)/d(x) === g(x)*y+h(x)
  695.  
  696. on one step. Notice that d(y)/d(x) must be alone on the left hand
  697. side of the equation. It is recommended to set the switch 
  698. expand=on and/or to include 'inte.sm' when solving the complicated 
  699. differential equations.
  700.  
  701.     Example 7.7.2.2 Solve d(y)/d(x)=== -sinh(x)*y+sinh(x)*cosh(x).
  702.     Input:
  703. dsolve(d(y)/d(x) === -sinh(x)*y+sinh(x)*cosh(x), y)
  704. end
  705.     Output:
  706. y === (constant + exp(cosh(x)) - cosh(x)*exp(cosh(x)))*exp(-cosh(x))
  707.  
  708.     Example 7.7.2.3 Solve differential equations. If the result is
  709. a polynomial, then rearrange the equation by solve().
  710.     Input:
  711. dsolve(d(y)/d(x) === x/(2+y), y)
  712. solve(last, y)
  713. end
  714.     Output:
  715. 2*y + 1/2*y^2 === constant + x^2
  716. y === [-2 + sqrt(4 - 2*(-constant - x^2)), -2 - sqrt(4 - 2*(-constant - x^2))]
  717.  
  718.     Example 7.7.2.4. Solve differential equations.
  719.     Input:
  720. dsolve(d(y)/d(x) === x*exp(y), y)
  721. dsolve(d(y)/d(x) === y^2+5*y+6, y)
  722. dsolve(d(y)/d(x) === y/x, y)
  723. dsolve(d(y)/d(x) === y*x+1, y)
  724. end
  725.     Output:
  726. -exp(-y) === constant + x^2
  727. ln((4 + 2*y)/(6 + 2*y)) === constant + x
  728. y === constant*x*sgn(x)
  729. y === exp(1/2*x^2)*(constant + sqrt(1/2)*sqrt(pi)*erf(sqrt(1/2)*x))
  730.  
  731.  
  732.           7.8 Sums and Products
  733.  
  734.     Users can compute partial, finite or infinite sums and 
  735. products. Sums and products can be differentiated and integrated. You 
  736. construct functions like Taylor polynomials or finite Fourier series.  
  737. The procedure is the same for sums as products so all examples will
  738. be restricted to sums.  The general formats for these functions are:
  739.  
  740.         sum(expr, x from xmin to xmax step dx)
  741.         prod(expr, x from xmin to xmax step dx)
  742.  
  743. The expression expr is evaluated at xmin, xmin+dx, ...  up to the last
  744. entry in the series not greater than xmax, and the resulting values
  745. are added or multiplied.  The part "step dx" is optional and defaults 
  746. to 1.  The values of xmin, xmax and dx can be any real number.
  747.  
  748. Here are some examples:
  749.      sum(j, j from 1 to 10)   
  750. for 1 + 2 + .. + 10.
  751.       sum(3^j, j from 0 to 10 step 2)  
  752. for 1 + 3^2 + ... + 3^10.
  753.       Here are some sample Taylor polynomials:
  754.     sum(x^j/j!, j from 0 to n)  
  755. for exp(x).
  756.     sum((-1)^j*x^(2*j+1)/(2*j+1)!, j from 0 to n)
  757. for sin(x) of degree 2*n+2.
  758.  
  759.     The package SUM.sm should be included before computing 
  760. partial and infinite sums, and the package PRODUCT.sm should be 
  761. included before computing partial and infinite products (see 8.8
  762. Infinite Sum Package).
  763.     Remember, the keywords "from", "to" and "step" can be 
  764. replaced by the comma (,).
  765.  
  766.  
  767.         7.9 Lists, Arrays, Vectors and Matrices
  768.  
  769.     SymbMath can construct lists of arbitrary length, and the 
  770. entries in the lists can be of any type of value whatsoever: 
  771. constants, expressions with undefined variables, or even other lists.  
  772. Lists are another kind of value in SymbMath, and they can be assigned 
  773. to variables just like simple values.  (Since variables in SymbMath 
  774. language are untyped, you can assign any value to any variable.).
  775.  
  776.  
  777.           7.9.1     Entering Lists
  778.  
  779.     To define a list, put its elements between square brackets:
  780.  
  781.          a = [1,2,3]
  782.          b = [f(2), g(1), h(1)]      # assumes f,g,h defined
  783.          c = [[1,2],3,[4,5]]
  784.  
  785.     A function can have a list for its value:
  786.          f(x) = [1,x,x^2]
  787.     You can define lists another way, with the list command:
  788.  
  789.          list(f(x), x from xmin to xmax step dx)
  790.  
  791.     This is similar to the sum command,  but the result is a list:
  792.            [f(xmin), f(xmin+dx), ..., f(xmin+x*dx), ...]
  793. which continues until the last value of xmin + x*dx  <= xmax.  
  794.     Try
  795.  
  796.          a = list(j^2, j from 0 to 10 step 1)
  797.          f(x) = list(x^j, j from 0 to 6 step 1)
  798.          b = f(-2)
  799.  
  800.       The third way to construct a list is to transform the sum to
  801. the list.
  802.  
  803.     Input:
  804. y1=[a,b,c]
  805. sum(y1)+d
  806. list(last)
  807. end
  808.     Output:
  809. y1 = [a, b, c]
  810. a + b + c + d
  811. [a, b, c, d]
  812.  
  813.       This is how you extend an existing list to include a new 
  814. element.
  815.  
  816.  
  817.           7.9.2     Accessing Lists
  818.  
  819.     To find the value of the j-th element in a list x, use the
  820. formula  x[j]. The first element of x is always  x[1].  If the x[j] 
  821. is itself a list, then its k-th element is accessed by repeating the 
  822. similar step. Try:
  823.  
  824.     Input:
  825. x = [[1,2],3,[4,5]]
  826. x[1]
  827. x[2]
  828. end
  829.     Output:
  830. x = [[1, 2], 3, [4, 5]]
  831. [1, 2]  
  832. 3
  833.  
  834.     An entire sub-list of a list x  can be accessed with the 
  835. command x[j], which is the list:
  836.           [x[j], x[j+1], ... ]
  837.  
  838.  
  839.           7.9.3     Modifying Lists
  840.  
  841.     The function subs() substitutes the value of the element in
  842. the list, as in the variables. e.g.
  843.  
  844.     Input:
  845. l=[a,b,c]
  846. subs(l, a=a0)
  847. end
  848.     Output:
  849. l = [a, b, c]
  850. [a0, b, c]
  851.  
  852.     But you can't use this form unless the element of the list is
  853. already defined.
  854.  
  855.  
  856.           7.9.4     List Operations
  857.  
  858.     Lists can be added, subtracted, multiplied, and divided by 
  859. other lists or by constants.  When two lists are combined, they are
  860. combined term-by-term, and the combination stops when the shortest 
  861. list is exhausted.  When a scalar is combined with a list, it is 
  862. combined with each element of the list.  Try:
  863.  
  864.      a = [1,2,3]
  865.      b = [4,5,6]
  866.      a + b
  867.      a / b
  868.      3 * a
  869.      b - 4
  870.  
  871.     Example 7.9.1. Two lists are added.
  872.     Input:
  873. list1=[a1,a2,a3]
  874. list2=[b1,b2,b3]
  875. list1+list2
  876. last[1]
  877. end
  878.     Output:
  879. list1 = [a1,a2,a3]
  880. list2 = [b1,b2,b3]
  881. [a1 + b1, a2 + b2, a3 + b3]
  882. a1 + b1
  883.  
  884.     If L is a list, then  f(L) results in a list of the values,
  885. even though f() is the differentiation or integration function d() or 
  886. inte(). Try list with:
  887.     Input:
  888. sqrt([a, b, c])
  889. d([x, x^2, x^3], x)
  890. end
  891.  
  892.     You can find the number of elements in a list with:
  893.         length(a)
  894.     If you use a list as the value of a variable in a user-
  895. defined function, SymbMath will try to use the list in the 
  896. calculation.  
  897.     You can sum all the elements in a list x with the user-
  898. defined function:
  899.  
  900.                listsum(x)
  901. in the statistics package 'stat.sm'.
  902.     Example:
  903.  
  904.             x=[1,2,3]
  905.             listsum(x^2)
  906.  
  907.     This functions takes the sum of the squares of the elements of
  908. the list x.
  909.     See the statistics package 'stat.sm' for other statistics 
  910. operations (e.g. average, max, min).
  911.     See the list plot package 'listplot.sm' for plotting a list.
  912.     
  913.           7.9.5     Vector Operations
  914.  
  915.     SymbMath uses lists to represent vectors, and lists of lists to
  916. represent matrices.
  917.     Vectors and matrices can be operated by "+" and "-" with vectors
  918. and matrixes, by "*" and "/" with a scalar, and by subs(), diff() and 
  919. inte(). These operations are on each element, as in lists and arrays.
  920.     You can use lists as vectors, adding them and multiplying them 
  921. by scalars. For example, the dot product of two vectors of a and b is:
  922.  
  923.                dot = listsum(a*b)
  924.  
  925.     You can even make this into a function:
  926.  
  927.                Dot(x_, y_) = listsum(x*y)
  928.                a = [2,3,5]
  929.                b = [4,3,2]
  930.                Dot(a,b)
  931.  
  932.     How about the cross product:
  933.  
  934. Cross(a,b) = [a[2]*b[3]-b[2]*a[3],a[3]*b[1]-b[3]*a[1],a[1]*b[2]-b[1]*a[2]]
  935.  
  936.      
  937.         7.10    Complex Analysis
  938.  
  939.     The complex numbers, complex infinity and some complex 
  940. functions can be calculated, and the complex expressions can be 
  941. differentiated and integrated.
  942.     Sign of complex numbers is defined as
  943.  
  944.      /  1    if re(z)>0, or re(z)=0 and im(z)>0, (i.e. z>0),
  945. sgn(z) =    0    if z=0,
  946.      \ -1    otherwise, (i.e. z<0).
  947.  
  948.     Example 7.10.1.
  949.     Input:
  950. sgn(1+i)
  951. sgn(1-i)
  952. sgn(-1-i)
  953. end
  954.     Output:
  955. 1
  956. 1
  957. -1
  958.  
  959.     Input:
  960. exp(inf+pi*i)
  961. ln(last)
  962. end
  963.     Output:
  964. -inf
  965. inf + pi*i
  966.  
  967.     Input:
  968. inte(1/x, x from i to 2*i)
  969. end
  970.     Output:
  971. ln(2)
  972.  
  973.         10.11     Tables of Function Values
  974.  
  975.     If you want to look at a table of values for a formula, you 
  976. can use the table command:
  977.  
  978.       table(f(x), x)
  979.       table(f(x), x from xmin to xmax)
  980.       table(f(x), x from xmin to xmax step dx)
  981.  
  982. It causes a table of values for f(x) to be displayed with x=xmin, 
  983. xmin+dx, ..., xmax.  If xmin, xmax, and step omit, then xmin=-5, xmax=5,
  984. and dx=1 for default. You can specify a function to be in table(), 
  985.     Example. Make a table of x^2.
  986.     Input:
  987. table(x^2, x)
  988. end
  989.     Output:
  990. -5,    25
  991. -4,    16
  992. -3,    9
  993. -2,    4
  994. :       :
  995. :       :
  996.  
  997.     Its output can be written into a disk file for interfacing
  998. with other software (e.g. the numeric computation software).
  999.  
  1000.  
  1001.         7.12 Transformation and Piece of Expressions
  1002.  
  1003.     Different types of data may be transformed each other.
  1004.     The complex number z is transformed to the real number x by
  1005.  
  1006.         re(z), im(z), abs(z), sgn(z).
  1007.  
  1008.     The functions
  1009.  
  1010.         left(x===a) and right(x===a)
  1011.  
  1012. pick up one side of the equation.
  1013.     A list can be transformed to a table with the table command if 
  1014. the elements of the list are the numbers. e.g.
  1015.     Input:
  1016. x=[5,4,3,2,1]
  1017. table(x[j], j from 1 to 4 step 1)
  1018. end
  1019.     Output:
  1020. 1,      5
  1021. 2,      4
  1022. 3,      3
  1023. 4,      2
  1024.  
  1025.     A piece of an expression can be picked up. e.g.
  1026.     Input:
  1027. y=a+b*x+c*x^2+d*x^3
  1028. coef(y, x)
  1029. coef(y, x^2)*x^2
  1030. list(y)
  1031. last[3]
  1032. end
  1033.     Output:
  1034. y = a + b*x + c*x^2 + d*x^3
  1035. b
  1036. c*x^2
  1037. [a, b*x, c*x^2, d*x^3]
  1038. c*x^2
  1039.  
  1040.  
  1041.     Table 7.2      Expand and Factor
  1042. ---------------------------------------------------------------------
  1043. Expand                  Factor
  1044.  
  1045. (a+b)^2                 a^2+2*a*b+b^2
  1046. (a+b)^n                 a^n+ ...... +b^n        n is positive integer
  1047. a*(b+c)                 a*b + a*c
  1048. ---------------------------------------------------------------------
  1049.     a+b can be many terms or a-b.
  1050.  
  1051.  
  1052.  
  1053.             7.13 Learning from Users
  1054.  
  1055.     One of the most important feature of SymbMath is its ability 
  1056. to deduce and expand its knowledge. If the user provides it with the 
  1057. necessary facts, SymbMath can solve many problems that it was unable 
  1058. to solve before. The followings are several ways in which SymbMath is 
  1059. able to learn from the user.
  1060.  
  1061.  
  1062. 7.13.1 Learning indefinite and definite integrals from a derivative
  1063.  
  1064.     Finding derivatives is much easier than finding integrals.
  1065. Therefore, you can find the integrals of a function from the 
  1066. derivative of that function.
  1067.     If the user provides the derivative of a known or unknown 
  1068. function, SymbMath can deduce the indefinite and definite integrals of 
  1069. that function. If the function is not a simple function, the user only
  1070. need to provide the derivative of its simple function. For example,
  1071. the user wants to evaluate the integral of f(a*x+b), the user only need
  1072. to provide d(f(x), x).
  1073.  
  1074. Example 7.13.1.1 :
  1075.  
  1076.     If a user know a derivative of an function f(x) (f(x) is a 
  1077. known or unknown function), SymbMath can learn the integrals of that 
  1078. function from its derivative.
  1079.     First check SymbMath wether or not it had already known 
  1080. indefinite and definite integrals of an unknown function f(x).
  1081.  
  1082. In the input window type :
  1083.  
  1084. inte(f(x), x)
  1085. inte(f(x), x, 1, 2)
  1086. end
  1087.  
  1088. In the output window you'll see :
  1089.  
  1090. inte(f(x), x)
  1091. inte(f(x), x, 1, 2)
  1092. end
  1093.  
  1094. As the output windows displayed only what was typed in the input 
  1095. windows without any computed results, imply that SymbMath has no 
  1096. knowlege of the indefinite and definite integrals of the functions 
  1097. in question. Now teach SymbMath the derivative of f(x) on the first 
  1098. line, and then run the program again.
  1099.  
  1100.     Input:
  1101. d(f(x_), x_) = exp(x)/x
  1102. inte(f(x), x)
  1103. inte(f(x), x, 1, 2)
  1104. end
  1105.     Output:
  1106. d(f(x_), x_) = e^x/x
  1107. x*f(x) - e^x
  1108. e - f(1) + 2*f(2) - e^2
  1109.  
  1110. As demonstrated, the user only supplied the derivative of the function
  1111. and in exchange SymbMath logically deduced its integral.
  1112.     An other example is
  1113.     Input:
  1114. d(f(x_) ,x_) := 1/sqrt(1-x^2)
  1115. inte(f(x), x)
  1116. inte(k*f(a*x+b), x)
  1117. inte(x*f(a*x^2+b), x)
  1118. end
  1119.     Output:
  1120. d(f(x_), x_) := 1/sqrt(1 - x^2)
  1121. sqrt(1 - x^2) + x*f(x)
  1122. k*(sqrt(1 - (b + a*x)^2) + (b + a*x)*f(b + a*x))/a
  1123. sqrt(1-(a*x^2 + b)^2) + (a*x^2 + b)*f(a*x^2 + b)
  1124.  
  1125.     The derivative of the function that user supplied can be another
  1126. derivative or integral.
  1127.  
  1128. Example 7.13.1.2 :
  1129.  
  1130.     Input window :
  1131. d(f(x_), x_) = inte(sin(x), x)
  1132. inte(f(x), x)
  1133. end
  1134.     Output window :
  1135. d(f(x_), x_) =  - cos(x)
  1136. cos(x)
  1137.  
  1138.  
  1139. 7.13.2 Learning complicated indefinite integrals from a simple 
  1140.     indefinite integral
  1141.  
  1142. The user supplies a simple indefinite integral, and in return, SymbMath 
  1143. will perform the related complicated integrals.
  1144.  
  1145. Example 7.13.2.1 :
  1146.  
  1147. Check whether SymbMath already knowns the following integrals or not.
  1148.  
  1149.     Input window :
  1150. inte(tan(x)^2, x)
  1151. inte((2*tan(x)^2+x), x)
  1152. inte(inte(tan(x)^2+y), x), y)
  1153. end
  1154.     Output window :
  1155. inte(tan(x)^2, x)
  1156. inte((2*tan(x)^2+x), x)
  1157. inte(inte(tan(x)^2+y), x), y)
  1158.  
  1159. Supply like in the previous examples the following in information
  1160. integral of tan (x) is tan (x) - x; then ask the indefinite integral 
  1161. of 2*tan(x)^2+x, and a double indefinite integral of 2*tan (x)^2 + x, 
  1162. and a double indefinite integral of respect to both x and y. Change 
  1163. the first line, and then the program again.
  1164.  
  1165.     Input window :
  1166. inte(tan(x)^2, x) = tan(x) - x
  1167. inte((2*tan(x)^2+x), x)
  1168. inte(inte(tan(x)^2+y), x), y)
  1169. end
  1170.     Output window :
  1171. inte(tan(x)^2, x) = tan(x) - x
  1172. 2*(tan(x) - x) + 1/2*x^2
  1173. tan(x)*y - x*y + x*y^2
  1174.  
  1175.     The user can also ask SymbMath to perform the following 
  1176. integrals: 
  1177. inte(inte(tan(x)^2+y^2), x), y), 
  1178. inte(inte(tan(x)^2*y), x), y), 
  1179. inte(x*tan(x)^2, x), 
  1180. triple integral of tan(x)^2-y+z, or others.
  1181.  
  1182.  
  1183.     7.13.3 Learning definite integral from indefinite integral
  1184.  
  1185.     The user continues to ask indefinite integral.
  1186.  
  1187.     Input window :
  1188. inte(inte(tan(x)^2+y, x from 0 to 1), y from 0 to 2)
  1189. end
  1190.     Output:
  1191. 2 tan(1)
  1192.  
  1193.  
  1194.     7.13.4 Learning complicated derivative from simple derivative
  1195.  
  1196. SymbMath can learn complicated derivatives from a simple derivative
  1197. even thought the function to be differentiated is any function, not
  1198. standard function.
  1199.  
  1200. Example 7.13.4.1 :
  1201.  
  1202. Differentiate f(x^2)^6, where f(x) is an known function, instead of 
  1203. a standard function.
  1204.  
  1205.     Input:
  1206. d(f(x^2)^6, x)
  1207. end
  1208.     Output:
  1209. 12*x*f(x^2)^5*d(f(x^2), x^2)
  1210.  
  1211. Output is only the part derivative. d(f(x^2), x^2) in the output 
  1212. suggest that the user should teach SymbMath d(f(x_), x_). e.g. the 
  1213. derivative of f(x) is another unknown function df(x), i.e. 
  1214. d(f(x_), x_) = df(x), do so and run it again.
  1215.  
  1216.     Input:
  1217. d(f(x_), x_) = df(x)
  1218. d(f(x^2)^6, x)
  1219. end
  1220.     Output:
  1221. d(f(x_), x_) = df(x)
  1222. 12*x*f(x^2)^5*df(x^2)
  1223.  
  1224. This time we get complete derivative.
  1225.  
  1226.     7.13.5 Learning integration from algebra
  1227.  
  1228. If the user shows SymbMath algebra, SymbMath can learn integrals.
  1229.  
  1230.  
  1231. Example 7.13.5.1 :
  1232.  
  1233. Input sin(x)^2=1/2-1/2*cos(2*x), then ask for the integral of sin(x)^2.
  1234.  
  1235.     Input window :
  1236. sin(x)^2=1/2-1/2*cos(2*x)
  1237. inte(sin(x)^2, x)
  1238. end
  1239.     Output window :
  1240. sin(x)^2 = 1/2 - 1/2*cos(2*x)
  1241. 1/2*x - 1/4*sin(2*x)
  1242.  
  1243. SymbMath is very flexible, It learned to solve these problems, even though
  1244. the types of problems are different, e.g. learning integrals from
  1245. derivatives or algebra.
  1246.  
  1247.  
  1248.     7.13.6 Learning complicated algebra from simple algebra
  1249.  
  1250. SymbMath has the ability to learn complicated algebra from simple algebra.
  1251.  
  1252. Example F1 :
  1253.  
  1254. Transform sin(x)/cos(x) into tan(x) in an expression.
  1255.  
  1256. input window:
  1257.  
  1258. sin(x)/cos(x) = tan(x)
  1259. x+sin(x)/cos(x)+a
  1260.  
  1261. Output window :
  1262. sin(x)/cos(x) = tan(x)
  1263. a + x + tan(x)
  1264.  
  1265.  
  1266.     The difference between learning and programming is as follows : 
  1267. the learning process of SymbMath is very similar to the way human 
  1268. beings learn, and that is accomplished by knowing certain rule that 
  1269. can be applied to several problems. Programming is diffrent in the way 
  1270. that the programmer have to accomplish many tasks before he can begin 
  1271. to solve a problem. First, the programmer defines many subroutines for 
  1272. the individual integrands (e.g. tan(x)^2, tan(x)^2+y^2, 2*tan(x)^2+x,
  1273. x*tan(x)^2, etc.), and for individual integrals (e.g. the indefinite
  1274. integral, definite integral, the indefinite double integrals,
  1275. indefinite triple integrals, definite double integrals, definite
  1276. triple integrals, etc.), second, write many lines of program for the
  1277. individual subroutines, (i.e. to tell the computer how to calculate
  1278. these integrals), third, load these subroutines, finally, call these
  1279. subroutines. That is precisely what SymbMath do not ask the user to do.
  1280.     In one word, programming means that programmers must
  1281. provide step-by-step procedures telling the computer how to solve
  1282. each problems. By contrast, learning means that users need only supply
  1283. the necessary facts, SymbMath will determine how to go about
  1284. solutions.
  1285.     If the learning is saved into the initial file init.sm, the 
  1286. learning  will become the knowledge of the SymbMath system, users need 
  1287. not to teach SymbMath again when users run SymbMath next time.
  1288.  
  1289.             
  1290.             8. Packages
  1291.     A package is a SymbMath program file for special use.
  1292.     In order to expand the special ability of SymbMath, some 
  1293. packages should be included in the user program by
  1294.         include('filename')
  1295.     The filename is any MS-DOS filename.
  1296.     It is recommended that the filename is the same as the function 
  1297. name in the program file, and the extension of the filename is .sm in 
  1298. order to remember easily the name of the package. e.g. inte.sm is the 
  1299. filename of the integral package as the name of integral function is 
  1300. inte().
  1301.     After including the package, users can call the functions in 
  1302. the package from their program.
  1303.     The include command must be in a single line anywhere.
  1304.     Many packages can be included at a time, however, all names of 
  1305. the variables are public and name conflicts must be avoided. 
  1306.     Alternately, a part of the package file rather than the whole
  1307. package file can be copied into the Edit window by pressing <F7> 
  1308. (external copy) in order to save memory space.
  1309.     There are many packages. The following are some of them.
  1310.  
  1311.         Table 8.1      Packages
  1312. ------------------------------------------------------------------------
  1313. File Name               Package Function
  1314.  
  1315. init.sm                 initial package when running the program in 
  1316.             the Edit window. It contains switches on the 
  1317.             default status.
  1318. plot.sm            plotting functions.
  1319. listplot.sm        plotting a list of data.
  1320. d.sm                    derivatives.
  1321. inte.sm                 integrals.
  1322.  
  1323. --------------- shareware version only has above packages --------------
  1324.  
  1325. units.sm                an units conversion.
  1326. trig.sm                 reduction of trig functions.
  1327. hyperbol.sm             reduction of hyerbolic functions.
  1328. dt.sm                   total derivatives.
  1329. NInte.sm                numeric integration.
  1330. NSolve.sm               numeric solver of equation.
  1331. ODE.sm            ordinary differential equation.
  1332. gamma.sm                gamma function.
  1333. ei.sm            exponential integral function.
  1334. series.sm        Taylor series.
  1335. sum.sm            symbolic sum.
  1336. InfSum.sm        infinite sum.
  1337. chemical.sm             the atomic weight of chemical elements.
  1338. inorgani.sm             inorganic chemical reactions.
  1339. -----------------------------------------------------------------------
  1340.     
  1341.  
  1342.         8.1 Initial Package
  1343. ---------------------------------------------------------------------
  1344. #    The initial package init.sm
  1345. output=off
  1346. numerical=off
  1347. expand=off
  1348. sum(y_,x_,a_,b_) := sum(y,x,a,b,1)
  1349. prod(y_,x_,a_,b_) := prod(y,x,a,b,1)
  1350. list(y_,x_,a_,b_) := list(y,x,a,b,1)
  1351. table(y_,x_,a_,b_) := table(y,x,a,b,1)
  1352. table(y_,x_) := table(y,x,-5,5,1)
  1353. degree=pi/180
  1354. 0!=1
  1355. inf!=inf
  1356. sgn(0)=0
  1357. sgn(zero)=1
  1358. sgn(e)=1
  1359. sgn(pi)=1
  1360. sgn(inf)=1
  1361. abs(zero)=zero
  1362. abs(e)=e
  1363. abs(pi)=pi
  1364. abs(inf)=inf
  1365. ln(0)=-inf
  1366. ln(inf)=inf
  1367.  include('plot.sm')
  1368. # include('d.sm')
  1369. block(output=basic,null)
  1370. end
  1371. ---------------------------------------------------------------------
  1372.  
  1373.     When running the program in the Edit window, SymbMath 
  1374. automatically first includes (or runs) the initial package 'init.sm'. 
  1375. The commands in the 'init.sm' package seems the SymbMath system 
  1376. commands. You can include other packages (e.g. d.sm) in the initial 
  1377. package 'init.sm' so the derivatives table in the package 'd.sm' seems 
  1378. to be in SymbMath system. Doing this is by changing the comment 
  1379. statement in the last third line 
  1380.         # include('d.sm')
  1381. to include statement
  1382.         include('d.sm')
  1383.  
  1384.  
  1385.         8.2 Derivative Package
  1386.        The package 'd.sm' is extention of the d(f(x),x) function.
  1387.  
  1388.         8.3 Total Derivative Package
  1389.        The package 'dt.sm' is for the total derivative function 
  1390. dt(f(x,y),x,y).
  1391.     Example:
  1392.     Input:
  1393. include('dt.sm')
  1394. dt(x*y, x, y)    
  1395. end
  1396.     Output:
  1397. y*d(x) + x*d(y)
  1398.     
  1399.         8.4 Integral Package
  1400.        The package 'inte.sm' is the extention of the function inte(f(x),x).
  1401.  
  1402.         8.5 Numeric Integration Package
  1403.     The function
  1404.         ninte(y, x from x0 to x1)
  1405. in the package 'NInte.sm' can do numerical integration.
  1406.     Example 8.5.1. Compare numerical and symbolic integrations 
  1407. for 4/(x^2+1) with respect to x taken from x=0 to x=1.
  1408.     Input:
  1409. include('NInte.sm')
  1410. ninte(4/(x^2+1), x from 0 to 1)
  1411. num(inte(4/(x^2+1), x from 0 to 1))
  1412. end
  1413.     Output:
  1414. done
  1415. 3.1415
  1416. 3.1416
  1417.         
  1418.         8.6 Numerical Solving
  1419.     The function 
  1420.         nsolve( f(x) === x, x, x0) 
  1421. in the package 'NSolve.sm' can numerically solve an algebraic equation 
  1422. with an initial value x0.
  1423.     Example 8.6.1. solve the equation sin(x) === 1 with x0=1.
  1424.     Input:
  1425. include('NSolve.sm')
  1426. nsolve( sin(x) === 1, x, 1)
  1427. end
  1428.     Output:
  1429. done
  1430. 1.5364150214
  1431.  
  1432.         8.7 Series Package
  1433.     The series package 'Series.sm' has a function series() for the 
  1434. Taylor series at x=0:
  1435.     You can call the function
  1436.         series(f(x), x, order)
  1437.         series(f(x), x)
  1438. to find the Taylor series. The arguement (order) is optional and 
  1439. defaults to 6.
  1440.     Example 8.7.1. Find the power series expansion for cos(x)
  1441. about the point x=0 to order x^4.
  1442.     Input:
  1443. include('series.sm')
  1444. series(cos(x), x, 4)
  1445. end
  1446.     Output:
  1447. 1 - 1/2*x^2 + 1/24*x^4
  1448.  
  1449.         8.8 Infinite Sum Package
  1450.     The infinite sum package 'InfSum.sm' has a function
  1451.         infsum(f(x),x)    
  1452. to find the infinite sum, sum(f(x), x from 0 to inf).
  1453.     Example:
  1454.     Input:
  1455. include('infsum.sm')
  1456. infsum(1/n!, n)
  1457. end
  1458.     Output:
  1459. e
  1460.             
  1461.         8.9 Chemical Calculation Package
  1462.     SymbMath recognizes 100 symbols of chemical elements and 
  1463. converts them into their atomic weights after the chemical package of
  1464. 'Chemical.sm' is included.
  1465.  
  1466.     Example 8.9.1. Calculate the weight percentage of the
  1467. element C in the molecule CH4.
  1468.     Input:
  1469. include('chemical.sm')
  1470. numerical=on
  1471. C/(C+H*4)*100*%
  1472. end
  1473.     Output:
  1474. done
  1475. numerical = on
  1476. 74.868 %
  1477.  
  1478.     Example 8.9.2. Calculate the molar concentration of CuO when
  1479. 3 gram of CuO is in 0.5 litre of a solution.
  1480.     Input:
  1481. include('chemical.sm')
  1482. numerical=on
  1483. g=1/(Cu+O)*mol
  1484. 3*g/(0.5*l)
  1485. end
  1486.     Output:
  1487. 0.07543*mol/l
  1488.  
  1489.         8.10 Chemical Reactions Package
  1490.     SymbMath can provide the answers for inorganic chemical 
  1491. reactions after the inorganic reaction package "Inorgani.sm" is included.
  1492.  
  1493.     Example 8.10.1.  What are the products when the reactors are
  1494. HCl + NaOH ?
  1495.     Input:
  1496. include('inorgani.sm')
  1497. HCl+NaOH
  1498. end
  1499.     Output:
  1500. H2O + NaCl
  1501.  
  1502.  
  1503.         8.11 Plot Function Package
  1504. ---------------------------------------------------------------------
  1505. # The plot function package plot.sm
  1506. # to plot a function.
  1507. # plot(x^2, x)        # plot the function of x^2
  1508. # plot(x^2, x,-6,6)    # plot the function of x^2 from x=-6 to x=6
  1509. # end
  1510.  
  1511. output=off
  1512. plot(y_,x_,x1_,x2_,dx_) := block(openfile('symbmath.out'),
  1513.     table(y,x,x1,x2,dx),
  1514.     closefile('symbmath.out'),
  1515.     system(plotdata))
  1516. plot(y_,x_,x1_,x2_) := plot(y,x,x1,x2,(x2-x1)*0.5)
  1517. plot(y_,x_) := plot(y,x,-5,5,0.5)
  1518. output=on
  1519. end
  1520. ----------------------------------------------------------------------
  1521.  
  1522.     If SymbMath is interfaced with the software PlotData, SymbMath 
  1523. produces the data table of functions, and PlotData plots from the 
  1524. table. So SymbMath seems to plot the function. This interface can be 
  1525. used to solve equations graphically.
  1526.     In the plot package 'plot.sm' the funcion
  1527.         plot(y, x, x1, x2, dx)
  1528. first open a file 'SymbMath.Out' for writing, then write the data table 
  1529. of the function y into the file 'SymbMath.out', then close the file, 
  1530. and finally automatically call the software PlotData to plot. After it 
  1531. exits from PlotData, it automatically return to SymbMath.
  1532.     The functions
  1533.         plot(y, x)
  1534.         plot(y, x from xmin to xmax)
  1535. call the function plot(y,x,x1,x2,dx)
  1536.     e.g. plot x^2.
  1537.     Input:
  1538. plot(x^2, x)
  1539. end
  1540.  
  1541. in the software PlotData, just select the option to read the file 
  1542. 'SymbMath.out' and to plot. PlotData read the data in the SymbMath 
  1543. format without any modification (and in many data format). 
  1544.     In PlotData, 
  1545. in the main menu:
  1546. 1 <Enter>
  1547. in the read menu:
  1548. 2 <Enter>
  1549. <Enter>
  1550. in the main menu:
  1551. 2 <Enter>
  1552. in the graph menu:
  1553. 1 <Enter>
  1554.  
  1555. where <Enter> is the <Enter> key.
  1556. Refer to PlotData for detail.
  1557.     Note that if your monitor is Hercules, you must load the 
  1558. MSHERC.COM program as a TRS program before you run PlotData. 
  1559. Otherwise you will get Error when you plot.
  1560.  
  1561.         8.12 List Plot Package
  1562. ----------------------------------------------------------------------
  1563. # the list plot package 'listplot.sm'
  1564. # to plot a list of data.
  1565. # listplot([1,2,3,4,5,4,3,2,1])
  1566. # end
  1567.  
  1568. output=off
  1569. listplot(y_) := if(islist(y), block(yy=y, length=length(yy),
  1570.     openfile('symbmath.out'),
  1571.     table(yy[xx],xx,1,length),
  1572.     closefile('symbmath.out'),
  1573.     system(plotdata) ))
  1574. output=on
  1575. end
  1576. ---------------------------------------------------------------------
  1577.         
  1578.         15. Interface with Other Software
  1579.     Interface with other software, (e.g. CurFit, Lotus 123) is 
  1580. similar to interface with the software PlotData in the plot package
  1581. 'plot.sm'.
  1582.  
  1583.                     (continued on the file SymbMath.DO3)
  1584.