home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / calculat / cc4_9206.zip / DEMO2.XPL < prev    next >
Text File  |  1992-06-07  |  5KB  |  308 lines

  1. // Demonstration file for X(PLORE) - Version 4
  2. 1
  3.  
  4. 1
  5. // This file demonstrates only those features  
  6. 1
  7.   that are new to X(PLORE).  The file
  8. 2
  9.   DEMO1.XPL demonstrates the features that
  10. 3
  11.   were already present in CC--The Calculus
  12. 4
  13.   Calculator
  14. 5
  15.  
  16. 1
  17. // Matrices
  18. 1
  19.  
  20. 1
  21. A = {1,2,3;4,5,6;7,9,8}  // 3 x 3 matrix
  22. 1
  23.  
  24. 1
  25. B = A"                   // Transpose of A
  26. 1
  27.  
  28. 1
  29. A + B                    // Sum
  30. 1
  31.  
  32. 1
  33. A*B                      // Product
  34. 1
  35.  
  36. 1
  37. A^(-1)                   // inverse of A
  38. 1
  39.  
  40. 1
  41. A/B                      // A*B^(-1)
  42. 1
  43.  
  44. 1
  45. A\B                      // A^(-1)*B
  46. 1
  47.  
  48. 1
  49. A = Random(3,5)          // 3 x 5 matrix
  50. 1
  51.  
  52. 1
  53. B = RREF(A)              // Row reduced form 
  54. 1
  55.  
  56. 1
  57. C = B[1:3, 4:5]          // submatrix
  58. 1
  59.  
  60. 1
  61. H = Matrix(1/(i+j-1),i = 1 to 4, j = 1 to 4)
  62. 1
  63.                          // Hilbert Matrix
  64. 1
  65.  
  66. 1
  67. H^3                      // third power
  68. 1
  69.  
  70. 1
  71. 1/H                      // inverse of H
  72. 1
  73.  
  74. 1
  75. P = CharPoly(H)          // Characteristic     
  76. 1
  77.                            polynomial
  78. 2
  79.  
  80. 1
  81. E = EigenVal(H)          // Eigenvalues
  82. 1
  83.  
  84. 1
  85. Rank(H - E[1]*Eye(4))    // Should be 3, since
  86. 1
  87.                            matrix - eigenvalue
  88. 2
  89.                            is singular
  90. 3
  91. F = Eig(H)               // F[1] is diagonal   
  92. 1
  93.                            matrix of eigen-   
  94. 2
  95.                            values, F[2] has   
  96. 3
  97.                            eigenvectors in    
  98. 4
  99.                            its columns.    
  100. 5
  101. F[2]*F[1]/F[2] - H       // Should be 0 or 
  102. 1
  103.                            nearly 0
  104. 2
  105.  
  106. 1
  107. // Level Curves
  108. 1
  109.  
  110. 1
  111. // We will graph the solution to               
  112. 1
  113.       3    3                                  
  114. 2
  115.      x  + y  = 1
  116. 3
  117.  
  118. 1
  119. Window(-3,3,-2,2)
  120. 1
  121. LevelC(x^3 + y^3 = 1, x=1, y=1)
  122. 1
  123.  
  124. 1
  125. // This level curve is a trajectory through    
  126. 1
  127.                       2      2
  128. 2
  129.   the vector field (3y , - 3x ).  Let's take 
  130. 3
  131.   a look at this vector field
  132. 4
  133.  
  134. 1
  135. Field(3y^2, -3x^2, x, y)
  136. 1
  137.  
  138. 1
  139. // Another trajectory through this field 
  140. 1
  141. starts at (-1.1, 1)
  142. 2
  143.  
  144. 1
  145. Traj(3y^2, -3x^2, x=-1.1, y=1, 100)
  146. 1
  147.  
  148. 1
  149. // Infinite precision numbers
  150. 1
  151.  
  152. 1
  153. // A number preceded by & is called an 
  154. 1
  155. infinite precision value and will be 
  156. 2
  157. maintained to infinite precision.  All 
  158. 3
  159. computations with infinite precision values 
  160. 4
  161. results in infinite precision values, and 
  162. 5
  163. quotients of infinite precision values are 
  164. 6
  165. stored as exact fractions reduced to lowest 
  166. 7
  167. terms. 
  168. 8
  169.  
  170. 1
  171. x = &3/&5                // fraction
  172. 1
  173.  
  174. 1
  175. y = &7/4 - &2/3          // exact arithmetic
  176. 1
  177.  
  178. 1
  179. z = &3^100               // huge integers
  180. 1
  181.  
  182. 1
  183. w = &100!                // very huge integers
  184. 1
  185.  
  186. 1
  187. H = Matrix(1/Fix(i+j-1),i = 1 to 4, j = 1 to 4)
  188. 1
  189.        // 4 x 4 Hilbert matrix.  The function  
  190. 1
  191.          FIX returns a Big Number.  Its       
  192. 2
  193.          complement is FLOAT
  194. 3
  195.  
  196. 1
  197. H*H                      // exact product
  198. 1
  199.  
  200. 1
  201. 1/H                      // exact inverse of H
  202. 1
  203.  
  204. 1
  205. //  New Three Dimensional Graphing Commands
  206. 1
  207.  
  208. 1
  209. Curve3d(cos(t), sin(t), t, t= 0 to 4pi)
  210. 1
  211.    // new command for parametric curves
  212. 1
  213.  
  214. 1
  215. H = Random(6,6)
  216. 1
  217. Matrixg(H)
  218. 1
  219.   // New command:  Graph the data in a matrix
  220. 1
  221.  
  222. 1
  223. // New string operations
  224. 1
  225.  
  226. 1
  227. q1 = 'abc'|'de'   // concatenation
  228. 1
  229. q2 = q1[3]        // single character
  230. 1
  231. q3 = q1[2:4]      // substring
  232. 1
  233. q4 = upcase(q1)   // upper case transform
  234. 1
  235. n = pos('de',q1)  // position of substring
  236. 1
  237. m = asc(q1)       // list of ascii codes
  238. 1
  239. q5 = chr(m)       // characters from codes
  240. 1
  241. n1 = val('123 + cos(4)')                       
  242. 1
  243.                  // value of a string
  244. 2
  245. q6 = str(123+cos(4))                           
  246. 1
  247.                  // string from a value
  248. 2
  249.  
  250. 1
  251. // See subroutine Intersect for new Input@ 
  252. 1
  253. command
  254. 2
  255.  
  256. 1
  257. Intersect
  258. 1
  259.  
  260. 1
  261. // procedure demonstrating use of Input@
  262. 1
  263.  
  264. 1
  265. Procedure Intersect
  266. 1
  267.   // user finds intersection of two curves
  268. 1
  269.   Window(0,3,-1,1)
  270. 1
  271.   graphics
  272. 1
  273.   quickg(cos(x),x)
  274. 1
  275.   sk(x,x)
  276. 1
  277.   solve(cos(b)=b,b=1)   // target for user to guess
  278. 1
  279.   Write@(.1,-.5,'Move crosshairs to intersection of curves, and')
  280. 1
  281.   Write@(.1,-.6,'enter x-coordinate where curves intersect')
  282. 1
  283.   Repeat
  284. 1
  285.       input@(.3,-.8,5,x)
  286. 1
  287.       ok = x > (b-0.05) and x < (b+0.05)
  288. 1
  289.       if not ok
  290. 1
  291.           beep
  292. 1
  293.         end
  294. 1
  295.     until ok
  296. 1
  297.   write@(.1,-.7,x)
  298. 1
  299.   write@(.1,-.8,'You got it!!')
  300. 1
  301.   text
  302. 1
  303. end  // Intersect          
  304. 1
  305.