home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / MCAD254.ZIP / STAT / SMOOTH.MCD < prev    next >
Encoding:
Text File  |  1988-12-03  |  2.5 KB  |  99 lines

  1. .MCD 20000 0
  2. .CMD PLOTFORMAT logs=0,0 subdivs=1,1 size=5,15 type=l
  3. .CMD FORMAT  rd=d ct=10 im=i et=3 zt=15 pr=3 mass length time charge
  4. .CMD SET ORIGIN 0
  5. .CMD SET TOL 0.001000
  6. .CMD MARGIN 0
  7. .CMD LINELENGTH 78
  8. .CMD SET PRNCOLWIDTH 8
  9. .CMD SET PRNPRECISION 4
  10. .TXT 0 41 1 39 
  11. a1,38,39,37
  12. Copyright (c) 1988 by MathSoft, Inc.
  13. .TXT 1 40 1 34 
  14. a1,33,78,32
  15. /EQUATIONS FOR MEDIAN SMOOTHING
  16. .TXT 1 -58 1 33 
  17. a1,32,77,31
  18. SMOOTHING WITH RUNNING MEDIANS
  19. .EQN 1 59 1 12 
  20. ORIGIN~0
  21. .TXT 0 15 1 57 
  22. a1,56,78,55
  23. Define a function to find the median of three numbers.
  24. .TXT 1 -95 2 76 
  25. a2,75,77,129
  26. This application illustrates the use of running medians to smooth a data 
  27. sequence.  First set the origin and read in the data. 
  28. .EQN 1 80 2 20 
  29. mx(a,b)~max(({2,1}÷b÷a))
  30. .EQN 2 -64 1 21 
  31. V~READPRN(RMDATA)
  32. .EQN 1 64 3 28 
  33. md(a,b,c)~min(({3,1}÷mx(a,c)÷mx(b,c)÷mx(a,b)))
  34. .TXT 1 -80 4 79 
  35. a4,78,76,270
  36. The smoothing replaces each term of the sequence by the median of that term 
  37. and its two neighbors.  This process is repeated until it produces no 
  38. further changes.  Press [F9] to calculate.  If the value of check isn't 
  39. zero, increase n and recalculate.               
  40. .TXT 4 79 2 81 
  41. a2,80,78,88
  42. The sequence to be smoothed is in elements zero through N of the array V.     
  43.         
  44. .TXT 1 -79 1 24 
  45. a1,23,76,22
  46. number of smoothings:
  47. .EQN 0 25 1 7 
  48. n~5
  49. .TXT 0 12 1 24 
  50. a1,23,39,22
  51. check for completion:
  52. .EQN 0 24 1 13 
  53. check=?
  54. .EQN 1 20 1 13 
  55. N~last(V)
  56. .EQN 0 27 1 11 
  57. k~0;N
  58. .TXT 1 -101 1 16 
  59. a1,15,71,14
  60. original data
  61. .TXT 0 39 1 16 
  62. a1,15,23,14
  63. smoothed data
  64. .EQN 1 -46 7 30 
  65. &&V[k{1,1,6,25,l}@N&0&k
  66. .EQN 0 38 7 30 
  67. &&W[k{1,1,6,25,l}@N&0&k
  68. .TXT 0 41 2 77 
  69. a2,76,75,141
  70. Initialize a two-column array for the smoothing.  Each iteration replaces 
  71. one column of the array A with a smoothed version of that column.
  72. .EQN 3 2 2 10 
  73. A{52}~V
  74. .EQN 0 13 2 10 
  75. A{52}~V
  76. .EQN 1 14 1 11 
  77. j~1;n
  78. .TXT 2 -28 1 15 
  79. a1,14,78,13
  80. [Ctrl][PgDn]
  81. .TXT 2 0 2 75 
  82. a2,74,76,123
  83. The index mod(j+1,2) is alternately 1 and 0, so the equation defining A 
  84. below writes alternately to columns 1 and 0 of A.
  85. .EQN 3 0 2 26 
  86. r(A,k,j)~A[(k,mod(j+1,2))
  87. .EQN 3 -2 3 82 
  88. A[(k,mod(j,2))~(j*0){54}if(mod(k,N)≈0,r(A,k,j),md(r(A,k-1,j),r(A,k,j),r(A,k+1,j)))
  89. .TXT 5 2 2 78 
  90. a2,77,78,119
  91. The process is complete when columns 0 and 1 of A are equal.  The smoothed 
  92. sequence is in column 0 and column 1 of A.
  93. .EQN 4 1 2 23 
  94. check~|(A{52}-A{52})
  95. .EQN 0 45 2 10 
  96. W~A{52}
  97. .EQN 1 -19 1 13 
  98. check=?
  99.