home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware City / Science / math-pad-235 / MP235 folder / MathPad 2.3 / MathPad 2.3.rsrc / TEXT_128.txt < prev    next >
Encoding:
Text File  |  1995-05-08  |  4.9 KB  |  136 lines

  1. ~                       MathPad 2.3
  2.  
  3. MathPad may be used as a calculator simply by typing in the numbers and operators. When the ENTER key is hit, each line is evaluated and the results are inserted into the text. Variables and functions can be defined. Results can be plotted or tabulated.  Command period can be used to stop evaluation.
  4. ~
  5. ----------------------- Examples:
  6. 21*(3+4)/2.4:61.2
  7.  
  8. 2 +     -- expressions are continued if the line ends with an operator
  9. 3*4:14.0
  10.  
  11. #+5:19.0;    -- # may be used to access the previous result
  12.  
  13. ------- variables and functions
  14. -- calculate a trajectory for initial velocity V, angle Theta.
  15. Vx=V*cos(Theta)
  16. Vy=V*sin(Theta) when Theta > 0 and Theta < 180, 0 otherwise
  17. altitude(t)=Vy*t-(g/2)*t^2
  18. impact_time=2*(Vy/g)
  19. apogee=(Vy^2)/(2*g);   range=Vx*impact_time
  20.  
  21. g=9.8; V=100;  Theta=75
  22.  
  23. range:510.2;    apogee:476.0
  24.  
  25. ------- plotting
  26. -- Special variables used to control plot:
  27.  --  X Xmin Xmax Xsteps Xdiv Xlabel 
  28.  --  Ymin Ymax Ydiv Ylabel Title Ystrips
  29. -- "newaxis" allows multiple plots/page
  30. plot altitude(X)
  31. Xmin=0; Xmax=impact_time
  32. label apogee:476.0
  33.  
  34. ------- tables
  35. -- Special variables used to control table:
  36.  --  N Nmin Nmax Nsteps 
  37. table     N,       N^3
  38.         1.0        1.0
  39.         2.0        8.0
  40.         3.0       27.0
  41.         4.0       64.0
  42.         5.0      125.0
  43.         6.0      216.0
  44.         7.0      343.0
  45.         8.0      512.0
  46.         9.0      729.0
  47.        10.0     1000.0
  48.  
  49. ------- summation
  50. series(n) = sum(2*k-1,k,1,n)
  51. series(9):81.0
  52.  
  53. ------- recursion
  54. fact(n) = 1 when n ‚⧠0, fact(n-1)*n
  55. fact(50):3.0e+64
  56.  
  57. ------- arrays
  58. A={10,20,30}      -- Defines a 3 element array.
  59. A[2]:20.0;     -- Accesses the 2nd element. Index values start at 1.
  60. B={A,{40,50,60},A+1}   --Multidimensional array.
  61. B:{{10.0,20.0,30.0},{40.0,50.0,60.0},{11.0,21.0,31.0}}
  62. B[1]:{10.0,20.0,30.0}
  63. B[1][2]:20.0
  64. B[1,2]:20.0;   -- Both forms of indexing are allowed
  65. A[2:3]:{20.0,30.0};    -- [lo:hi] selects a sub array.
  66. A[:2]:{10.0,20.0};     -- lo and/or hi may be omitted.
  67.  
  68. Q[i]=i*11  --Arrays can be defined in terms of their index values.
  69. Q[2]:22.0
  70. -- dim[] can be used to set the number of elements
  71. I[i,j] = 1 when i=j, 0   dim[3,3]
  72. I:{{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}}
  73.  
  74. --Arrays may be used freely in expressions. Operations are performed on each element.
  75. A+Q:{21.0,42.0,63.0}
  76. 2+A:{12.0,22.0,32.0}
  77. log(A):{1.0,1.3,1.5}
  78. A*Q:{110.0,440.0,990.0}; --Note: this is not matrix multiply
  79. --Q[A]:? A[?];           --Arrays may not be used as index values
  80.  
  81. --Functions can use index values
  82. skip(zz,by)[i] = zz[i*by] dim[count(zz)/by]
  83. skip(A,3):{30.0}
  84. skip(Q,2):{22.0,44.0,66.0,...}
  85. multiply(A,B)[i,j] = sum(A[i,k]*B[k,j],k,1,count(B)) dim
  86.              [count(A),count(B[1])]
  87. multiply({A},I):{{10.0,20.0,30.0}}
  88.  
  89. --Built-in functions for arrays
  90. count(A):3.0;  -- count() returns the number of array elements
  91.  count(B):3.0;  -- elements in 1st dimension
  92.  count(42):0.0; -- scalar
  93.  count(Q):?;    -- infinite array
  94. det(B):580.0;  -- calculates the determinant of a square matrix
  95. --read("pathname") returns an array of values read from the named file.
  96. --write("pathname",array)  writes the elements of the array to the named file.
  97.  
  98. --------- The table command can print 1D or 2D arrays
  99. table B
  100.        10.0       20.0       30.0
  101.        40.0       50.0       60.0
  102.        11.0       21.0       31.0
  103.  
  104. --------- The plot command can plot 1D or 2D arrays
  105. --To connect the points, use "plotline" instead of "plot".
  106. --For 1D {y1,y2,y3...} the element values are used for y. X is stepped from Xmin to Xmax as usual. 
  107. -- 2D arrays can be given in 3 forms:
  108.  -- array of x,y pairs  {{x1,y1},{x2,y2},{x3,y3},...}
  109.  -- a pair of arrays    {{x1,x2,...},{y1,y2,...}}
  110.  -- a pair of functions {fx(X),fy(X)}
  111. -- For 2D arrays both x and y are taken from the array. X is stepped from 0 to 1.0 and can be used for parametric equations:
  112.  
  113. deg=X*360; Xsteps=36      -- run deg from 0 to 360 in 10¬∞ steps
  114. x(angle)=5*cos(angle)+10  -- arbitrary scale to fit on existing plot
  115. y(angle)=100*sin(angle)+200
  116. plot {x(deg),y(deg)}
  117.  
  118. --------- The image command can display 2D arrays
  119. img[i,j]=(i-10)^2-5*j^2 dim[20,20]
  120. image img
  121. Zmax=95; Zmin=-500
  122.  
  123. --------- assignments
  124. -- The assignment operator := evaluates the right hand side expression and replaces any previous definition of the left hand variable with the result. Accessing the variable gives its current value.
  125. -- Assignments can only be done to simple global variables.
  126. -- Finite arrays may be assigned. A single numeric value can be assigned to an element of an array that has previously been initialized by assignment.
  127. -- The result of the := operation itself is always unknown. If you wish to access the result you must use the variable name. Multiple assignments can be performed using comma separated lists.
  128.  
  129. --------- iteration
  130. -- The 'while' operator can be used to evaluate some expression repeatedly.
  131.  
  132. factorial(n) = i:=1,m:=1,(i:=i+1,m:=m*i) while i<n, m
  133. factorial(400):6.4e+868
  134.  
  135. --------- include files
  136. -- include "pathname"  will open and read definitions from the specified file.