home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / calculat / cc4_9206.zip / DEMO1.XPL next >
Text File  |  1992-06-07  |  10KB  |  623 lines

  1. // This file will help you learn to use 
  2. 1
  3. // X(PLORE).
  4. 1
  5.  
  6. 1
  7. // Lines following // are called COMMENTS and
  8. 1
  9. // are ignored by X(PLORE).  Comments can be 
  10. 1
  11. // used to annotate your calculations.
  12. 1
  13.  
  14. 1
  15. // As you read this file, place the cursor on
  16. 1
  17. // each line and push <Enter>.  That will cause
  18. 1
  19. // the line to be executed, so you will be able
  20. 1
  21. // to see what it does.
  22. 1
  23.  
  24. 1
  25. 2+3   // execute this line
  26. 1
  27.  
  28. 1
  29. // If you executed 2+3, you saw 5 as the ANSwer
  30. 1
  31. // and the Last Result.  Enter your own formula
  32. 1
  33. // on the blank line below and execute it.
  34. 1
  35.  
  36. 1
  37. // Anytime you want to interrupt this lesson to
  38. 1
  39. // try a function of your own, just push 
  40. 1
  41. // Control-Enter a few times to open up empty
  42. 1
  43. // lines in the window.  Try pushing it now.
  44. 1
  45. // To erase a line, put the cursor on it and
  46. 1
  47. // press Control-Y.  Altering the screen will 
  48. 1
  49. // not change the file DEMO.X(PLORE) on your
  50. 1
  51. // disk.
  52. 1
  53.  
  54. 1
  55. // You can use transcendental functions with
  56. 1
  57. // X(PLORE). Try the following lines:
  58. 1
  59.  
  60. 1
  61. 3.6^2.1   // ^ means exponentiation
  62. 1
  63. Sin(2.4)
  64. 1
  65. Exp(-30)  // very large and small numbers are  
  66. 1
  67.            represented in exponential notation
  68. 2
  69. ln(1.3)   // natural logarithm
  70. 1
  71. sin(3.4)-4*ln(2.7)   //* means multiply
  72. 1
  73. sqrt(18.27)   // sqrt means square root
  74. 1
  75.  
  76. 1
  77. // X(PLORE) includes an on-line help facility.
  78. 1
  79. // To read about X(PLORE)'s functions, press
  80. 1
  81. // function key F1 and choose topic H.
  82. 1
  83. // Push <ESC> to leave Help and return here.
  84. 1
  85.  
  86. 1
  87. // X(PLORE) can calculate with complex numbers.
  88. 1
  89. // If you are interested in complex math, try
  90. 1
  91. // the following lines.
  92. 1
  93.  
  94. 1
  95. (1+î)/(3-4î)  // enter î=sqrt(-1) with alt-i
  96. 1
  97. exp(3+4î)
  98. 1
  99. Asin(3)    // real argument, complex result
  100. 1
  101. Ln(-1)
  102. 1
  103.  
  104. 1
  105. // You can assign the result of a calculation
  106. 1
  107. // to a variable.  Watch the Output window as
  108. 1
  109. // you execute these lines:
  110. 1
  111.  
  112. 1
  113. a = 4
  114. 1
  115. b = (3.2 - 5.4)/2.1
  116. 1
  117. c = a-3 //variables can be used in calculations
  118. 1
  119.  
  120. 1
  121. // Test yourself -- answers at end of file
  122. 1
  123. // 1.  Find the hypotenuse of a right triangle 
  124. 1
  125.       with legs of length 3.8 and 7.2.
  126. 2
  127.  
  128. 1
  129.  
  130. 1
  131. // 2.  What is the final balance if $5000 is   
  132. 1
  133.       invested at 7% for 8 years
  134. 2
  135.  
  136. 1
  137.  
  138. 1
  139. // You can also define functions with X(PLORE),
  140. 1
  141. // which can be evaluated, graphed, integrated,
  142. 1
  143. // differentiated, and solved for roots.
  144. 1
  145.  
  146. 1
  147. f(x) = x^2 + sin(x)  // execute this line to   
  148. 1
  149.                        define f(x)
  150. 2
  151.  
  152. 1
  153. y = f(2)
  154. 1
  155. z = 3+f(sin(y))
  156. 1
  157.  
  158. 1
  159. // There are now more variables defined than
  160. 1
  161. // can be shown.  Use function keys F5 and F6
  162. 1
  163. // to scroll the output window.
  164. 1
  165.  
  166. 1
  167. // Now we will graph f(x).  Push <Enter> when  
  168. 1
  169.   you wish to stop viewing the graph and      
  170. 2
  171.   return to this screen.
  172. 3
  173.  
  174. 1
  175. graph(f(x),x)
  176. 1
  177.  
  178. 1
  179. // To see more or less of the curve, you can 
  180. 1
  181. // alter the viewing window with the WINDOW
  182. 1
  183. // command.  The syntax is 
  184. 1
  185. //    WINDOW(xmin, xmax, ymin, ymax)
  186. 1
  187.  
  188. 1
  189. Window(-3,3,-.5,10)
  190. 1
  191. Graph(f(x),x)
  192. 1
  193.  
  194. 1
  195. // Compare to curve y = x^2
  196. 1
  197.  
  198. 1
  199. Graph(x^2,x)
  200. 1
  201.  
  202. 1
  203. // You can graph any expression like f(x) or
  204. 1
  205. // x^2 or even x^2*f(x).  
  206. 1
  207. // You can display as many curves as you want 
  208. 1
  209. // on one graph.  To erase the graph and start
  210. 1
  211. // over, enter the command ERASE or resize the
  212. 1
  213. // window with WINDOW.
  214. 1
  215.  
  216. 1
  217. // Read more about graphing in the help file.
  218. 1
  219.  
  220. 1
  221. // To differentiate the function f(x) at x=3,  
  222. 1
  223.   i.e. to calculate f'(3), enter the command
  224. 2
  225.  
  226. 1
  227. d1 = dif(f(x),x=3)
  228. 1
  229.  
  230. 1
  231. // You can also differentiate an expression
  232. 1
  233.  
  234. 1
  235. d2 = dif(x^2+sin(x),x=3)   // will equal d1
  236. 1
  237.  
  238. 1
  239. // You can define one function to be the       
  240. 1
  241.   derivative of another
  242. 2
  243.  
  244. 1
  245. g(x) = dif(f(x),x)
  246. 1
  247. window(-1,1,-1,3)
  248. 1
  249. graph(f(x),x)
  250. 1
  251. graph(g(x),x)
  252. 1
  253. Write@(0.6,0.85,'F(x)')  // graphs can be 
  254. 1
  255. Write@(0.5,1.75,'dF/dx') // labeled
  256. 1
  257.  
  258. 1
  259. // To see the symbolic derivative of f(x),     
  260. 1
  261.   differentiate f(x) with respect to an       
  262. 2
  263.   undefined variable name.
  264. 3
  265.  
  266. 1
  267. df = dif(f(w),w)
  268. 1
  269.  
  270. 1
  271. // To find where the graph of x^2+sin(x)       
  272. 1
  273.   crosses the x-axis, we solve the equation   
  274. 2
  275.   f(p) = 0
  276. 3
  277.  
  278. 1
  279. Solve(f(p)=0, p=-1)   // p=-1 is first guess
  280. 1
  281.  
  282. 1
  283. // Recall what the graph of f(x) looks like by 
  284. 1
  285.   pressing function key F9 to review the last 
  286. 2
  287.   graph.  To find the area between the graph  
  288. 3
  289.   of f(x) and the x-axis, we integrate f(x)   
  290. 4
  291.   between p (where the graph crosses the x-   
  292. 5
  293.   axis) and 0. 
  294. 6
  295. // This would not be possible without first    
  296. 1
  297.   solving for p.
  298. 2
  299.  
  300. 1
  301. Area := -IN(f(x),x=p to 0)
  302. 1
  303.  
  304. 1
  305. // X(PLORE) includes a version of the
  306. 1
  307.   integration operator, INTEG, that shows a
  308. 2
  309.   graph of the area being integrated.  It
  310. 3
  311.   returns the same answer as the ordinary
  312. 4
  313.   integration operator IN.
  314. 5
  315.  
  316. 1
  317. Area = -INTEG(f(x),x=p to 0)
  318. 1
  319.  
  320. 1
  321. // X(PLORE) will graph parametric and polar
  322. 1
  323.   equations.  It will also graph surfaces in
  324. 2
  325.   three dimensions.  You can read about all  
  326. 3
  327.   these operations in the help file.  Here's 
  328. 4
  329.   an example of 3D graphing.
  330. 5
  331.  
  332. 1
  333. Graph3d(2x^2-y^2, x=-1,1, y=-1,1)
  334. 1
  335.  
  336. 1
  337. // You can change the shading of 3d graphs by  
  338. 1
  339.   pressing the keys 1 (opaque--what you see   
  340. 2
  341.   first), 2 (striped), 3 (striped the other   
  342. 3
  343.   way), 4 (transparent).  Press F9 to recall  
  344. 4
  345.   the last graph, then press the number keys  
  346. 5
  347.   to change its shading.
  348. 6
  349.  
  350. 1
  351. // You can also rotate the 3d graph on the     
  352. 1
  353.   screen by pressing the keys x, X, y, Y, z, Z
  354. 2
  355.  
  356. 1
  357. // Test yourself
  358. 1
  359. // 3.  Graph the curve cos(x)-x.  Find the     
  360. 1
  361.       intersections of this curve with the x- 
  362. 2
  363.       axis, the area between the curve and the
  364. 3
  365.       x-axis, and the slope of the curve where
  366. 4
  367.       it crosses the x-axis.
  368. 5
  369.  
  370. 1
  371.  
  372. 1
  373.  
  374. 1
  375.  
  376. 1
  377. // 4.  Find the first three points to the right
  378. 1
  379.       of the y-axis where the line y = x meets
  380. 2
  381.       the graph of y = tan(x).
  382. 3
  383.  
  384. 1
  385.  
  386. 1
  387.  
  388. 1
  389.  
  390. 1
  391. // If you aren't interested in vectors, skip   
  392. 1
  393.   the next section.  X(PLORE)3 will do vector
  394. 2
  395.   arithmetic and other operations with arrays
  396. 3
  397.   and lists.  Note that if you define
  398. 4
  399.  
  400. 1
  401. v = (3, 5, 6)   // execute this line
  402. 1
  403.  
  404. 1
  405. // v is displayed in the output window as three
  406. 1
  407.   parts: v[1], v[1], v[3].
  408. 2
  409. // Let's do some vector arithmetic.
  410. 1
  411.  
  412. 1
  413. w = (4, 6, 3)
  414. 1
  415.  
  416. 1
  417. u = v+w
  418. 1
  419.  
  420. 1
  421. u = 5*v
  422. 1
  423.  
  424. 1
  425. u = v^2
  426. 1
  427.  
  428. 1
  429. u = v*w  
  430. 1
  431.  
  432. 1
  433. // X(PLORE) is not just a calculator.  It is
  434. 1
  435.   also a programming environment.   Push
  436. 2
  437.   function key F10 to view the Subroutine 
  438. 3
  439.   Window, where X(PLORE)'s programs are   
  440. 4
  441.   written, then push F10 again to return to 
  442. 5
  443.   this screen.
  444. 6
  445.  
  446. 1
  447. // Now that you have viewed the Scratchpad,    
  448. 1
  449.   execute the function PC(x,n)
  450. 2
  451.  
  452. 1
  453. a1=PC(1,10)    // approximate solution
  454. 1
  455. a2 = sin(1)    // exact solution
  456. 1
  457.  
  458. 1
  459. a3 = PC(1,20)  // better approximation
  460. 1
  461. a4 = PC(1,100) // excellent approximation
  462. 1
  463.  
  464. 1
  465. // The algorithm fails for x > 1.5 because
  466. 1
  467. // X(PLORE always computes positive square
  468. 1
  469. // roots.
  470. 1
  471.  
  472. 1
  473. // The manual has many more examples of using  
  474. 1
  475.   programming with X(PLORE).
  476. 2
  477.  
  478. 1
  479. // These notes have not mentioned the          
  480. 1
  481.   constructors SUM, PRODUCT, and LIST;
  482. 2
  483.   X(PLORE)'s statistical features; symbolic
  484. 3
  485.   calculations; saving work with disk and
  486. 4
  487.   printer; or advanced programming techniques.
  488. 5
  489. // All these points are explained in the manual
  490. 1
  491.  
  492. 1
  493. // *** Answers to Test Yourself ***
  494. 1
  495.  
  496. 1
  497. Ans1 = sqrt(3.8^2 + 7.2^2)
  498. 1
  499.  
  500. 1
  501. Ans2 = 5000*(1.07)^8
  502. 1
  503.  
  504. 1
  505. // Ans3
  506. 1
  507. f(x) = cos(x)-x
  508. 1
  509. window(0,1,-1,1)
  510. 1
  511. graph(f(x),x)
  512. 1
  513. solve(f(p)=0,p=1)       // curve crosses x-axis
  514. 1
  515. Ans3_1 = in(f(x),x=0,p)  // area
  516. 1
  517. Ans3_2 = dif(f(x),x=p)     // slope
  518. 1
  519.  
  520. 1
  521. // Ans4
  522. 1
  523. window(0,12,0,12)
  524. 1
  525. graph(tan(x),x)
  526. 1
  527. graph(x,x)
  528. 1
  529. // using the crosshairs, we see that the x-    
  530. 1
  531.   coordinates of the intersections are approx-
  532. 2
  533.   imately 4.504, 7.735, 10.893
  534. 3
  535. solve(Tan(x)=x, x=4.505)
  536. 1
  537. Ans4_1 = x
  538. 1
  539. solve(tan(x)=x, x=7.735)
  540. 1
  541. Ans4_2 = x
  542. 1
  543. solve(tan(x)=x, x=10.893)
  544. 1
  545. Ans4_3 = x
  546. 1
  547. // This is X(PLORE)'s Subroutine Window, where you can write programs using
  548. 1
  549. // its built-in progamming language.
  550. 1
  551.  
  552. 1
  553. // One warning.  If you push <Enter> while in the Subroutine Window, you 
  554. 1
  555. will split the line you are on at the cursor and push the lines below the 
  556. 2
  557. cursor down one line.  To avoid rearranging the lines in the Scratchpad, 
  558. 3
  559. use the up- and down-arrow keys to move the cursor around the Scratchpad.
  560. 4
  561.  
  562. 1
  563. // Below is a sample program that uses the predictor-corrector method to
  564. 1
  565. // compute the solution to the differential equation:
  566. 1
  567.  
  568. 1
  569. //              y'(t) = sqrt(1-y(t)^2)
  570. 1
  571. //              y(0) = 0
  572. 1
  573.  
  574. 1
  575. // Of course, the exact solution is y(t) = sin(t).  To execute this program,
  576. 1
  577. // push function key F10 to return to the calculator window and follow the
  578. 1
  579. // instructions there.
  580. 1
  581.  
  582. 1
  583.  
  584. 1
  585. Function PC(x,n)
  586. 1
  587. // use n-step predictor corrector method to solve the initial value problem  
  588. 1
  589.   above and return the estimated value for y(x).
  590. 2
  591.   dt = x/n             // use n steps between 0 and x
  592. 1
  593.   t = 0                // starting value for t
  594. 1
  595.   y = 0                // initial value for y
  596. 1
  597.   f(y) = sqrt(1-y^2)   // f(y) is slope of y(t) 
  598. 1
  599.   for j = 1 to n do
  600. 1
  601.       slope1 = f(y)    
  602. 1
  603.       y1 = y + slope1*dt   // first estimate for next value of y
  604. 1
  605.       slope2 = f(y1)
  606. 1
  607.       avgslope = (slope1+slope2)/2
  608. 1
  609.       y = y+avgslope*dt    // corrected estimate for next value of y
  610. 1
  611.     end
  612. 1
  613.   return(y)
  614. 1
  615. end      
  616. 1
  617.  
  618.  
  619.