home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / MBUG / MBUG058.ARC / STANDEV.BAS < prev    next >
BASIC Source File  |  1979-12-31  |  3KB  |  118 lines

  1. 5  REM
  2. 10 REM standard deviation program main
  3. 15 REM  By Ralph Johnson  1-1982
  4. 16 REM
  5. 20 GOSUB 500        REM setup and title
  6. 30 GOSUB 1000        REM inputs
  7. 40 GOSUB 1500         REM standard deviation
  8. 50 GOSUB 2000        REM data rejection
  9. 60 GOSUB 2500        REM output
  10. 70 INPUT"Do you have more data (y/n)"; LOOP$
  11. 80 IF LOOP$ = "n" OR LOOP$="N"THEN GOTO 100
  12. 90 GOSUB 3000         REM reset
  13. 95 GOTO 30
  14. 100 STOP
  15. 110 REM     end main
  16. 120 REM
  17. 500 REM setup and titles
  18. 510 DIM A(50),B(50): PRINT CHR$(&H1A)
  19. 520 PRINT"************ Standard Deviation ************"
  20. 530 PRINT:PRINT
  21. 540 PRINT"    This program will give the mean and "
  22. 550 PRINT"standard deviation of a set of data.  It will"
  23. 560 PRINT"also reject bad data according to Chuavenet's"
  24. 565 PRINT "criteria on your direction."
  25. 570 PRINT: PRINT "Number of entries is limited to 50. See text."
  26. 580 PRINT:PRINT:PRINT
  27. 590 INPUT"Hit return to begin";A$
  28. 600 PRINT CHR$(&H1A)
  29. 610 RETURN
  30. 620 REM        end setup and titles
  31. 630 REM
  32. 1000 REM  inputs
  33. 1010 INPUT"How many data points are there";N%
  34. 1020 PRINT CHR$(&H1A)
  35. 1030 PRINT"Now enter the data":PRINT:PRINT
  36. 1040 FOR I%=1 TO N%
  37. 1050     PRINT"x(";I%;")";
  38. 1060     INPUT A(I%)
  39. 1070     B(I%)=A(I%)
  40. 1080 NEXT I%
  41. 1090 REM corrections
  42. 1100 PRINT CHR$(&H1A)
  43. 1110 PRINT "This is the entered data":PRINT
  44. 1120 FOR I%=1 TO N%
  45. 1130    PRINT I%,A(I%)
  46. 1140    IF I%/20<>INT(I%/20) THEN GOTO 1160
  47. 1150    INPUT"Hit enter to continue";A$
  48. 1160 NEXT I%
  49. 1170 INPUT"Is there any bad data (y/n)"; FLAG$
  50. 1180 IF FLAG$ <> "y" AND FLAG$ <> "Y" THEN GOTO 1260
  51. 1190 INPUT "How many points";BAD%
  52. 1200 FOR I%=1 TO BAD%
  53. 1210    INPUT"Enter the loc. of one bad number";J%
  54. 1220    INPUT"Enter the correct number";A(J%)
  55. 1230    B(J%)=A(J%)
  56. 1240 NEXT I%
  57. 1250 GOTO 1100
  58. 1260 RETURN
  59. 1270 REM    End inputs
  60. 1280 REM
  61. 1500 REM Standard Deviation
  62. 1510 SD=0
  63. 1520 XB=0
  64. 1530 FOR I%=1 TO N%   
  65. 1540     XB=B(I%)/N%+XB
  66. 1550 NEXT I%
  67. 1560 FOR I%=1 TO N%
  68. 1570    SD=(B(I%)-XB)^2/(N%-1)+SD
  69. 1580 NEXT I%
  70. 1590 SD=SD^.5
  71. 1600 PRINT CHR$(&H1A): PRINT: PRINT
  72. 1610 PRINT "The mean of this data is:";XB
  73. 1620 PRINT "Standard deviation is :";SD
  74. 1630 RETURN
  75. 1640 REM    End standard deviation
  76. 1650 REM
  77. 2000 REM Data rejection
  78. 2010 PRINT:PRINT
  79. 2020 INPUT"Do you want to check for bad data (y/n)";DR$
  80. 2030 IF DR$="n" OR DR$="N" THEN RETURN
  81. 2040 XS=-6.54032E-07*N%^4+8.67668E-05*N%^3
  82.        -4.30534E-03*N%^2+.106983*N%+1.235
  83. 2050 MA=B(1)
  84. 2060 MT=MA
  85. 2070 FOR K%=2 TO N%
  86. 2080     IF B(K%)>MA THEN MA=B(K%) :K1%=K%
  87. 2090     IF B(K%)<MT THEN MT=B(K%) :K2%=K%
  88. 2100 NEXT K%
  89. 2110 D1=(MA-XB)/SD
  90. 2120 D2=(XB-MT)/SD
  91. 2125 R1$=" ": R2$=" "
  92. 2130 IF D1>XS THEN PRINT B(K1%);"is bad","x/s=";D1, "x/s max=";XS ELSE GOTO 2150
  93. 2140 INPUT"Do you want to reject this pt. (y/n)";R1$
  94. 2150 IF D2>XS THEN PRINT B(K2%);"is bad","x/s=";D2,"x/s max=";XS ELSE GOTO 2170
  95. 2160 INPUT"Do you want to reject this pt. (y/n)";R2$
  96. 2170 IF R1$<>"y" AND R1$<>"Y"THEN GOTO 2210
  97. 2180 B(K1%)=B(N%)
  98. 2190 B(N%)=0
  99. 2200 N%=N%-1
  100. 2210 IF R2$<>"y" AND R2$<>"Y"THEN GOTO 2250
  101. 2220 B(K2%)=B(N%)
  102. 2230 B(N%)=0
  103. 2240 N%=N%-1
  104. 2250 IF R1$="y" OR R2$="y" OR R1$="Y" OR R2$="Y"
  105.      THEN GOSUB 1500 ELSE GOTO 2270
  106. 2260 GOTO 2000
  107. 2270 PRINT"No bad data"
  108. 2275 RETURN
  109. 2290 REM    end data reject
  110. 2300 REM
  111. 2500 RETURN
  112. 3000    REM Reset
  113. 3010 FOR I%= 1 TO 50 
  114. 3020    A(I%)=0
  115. 3030    B(I%)=0
  116. 3040 NEXT I%
  117. 3050 RETURN
  118.