10 PRINT "ROOTS OF POLYNOMIALS: HALF-INTERVAL SEARCH"
20 PRINT
30 REM - ENTER FUNCTION ("DEFFNR(x)="FUNCTION") HERE
35 DEF FNR(X)=4*X[4-2.5*X[2-X+.5
40 DIM D(3)
50 PRINT "(TO END SEARCH ENTER 0,0)"
59 REM - ESTABLISH INTERVAL OF RANDOM SEARCH
60 PRINT "INTERVAL (LOWER, UPPER LIMIT)";
70 INPUT A,B
79 REM - TEST FOR USABLE LIMITS ENTERED
80 IF A<>B THEN 120
89 REM - END PROGRAM?
90 IF A=0 THEN 430
100 PRINT "--INTERVAL LIMITS CANNOT BE EQUAL--"
110 GOTO 60
120 IF A<B THEN 150
130 PRINT "--LOWER LIMIT MUST BE ENTERED FIRST--"
140 GOTO 60
150 A1=SGN(FNR(A))
160 B1=SGN(FNR(B))
169 REM - TEST FOR ROOT AT EITHER LIMIT
170 IF A1*B1=0 THEN 360
179 REM - TEST FOR OPPOSITE SIGNS AT INTERVAL LIMITS
180 IF A1*B1<0 THEN 280
189 REM - LOOP TO SEARCH 1000 NUMBER FOR OPPOSITE SIGNS IN FUNCTION
190 FOR I=1 TO 1000
200 X=A+RND(2)*(B-A)
210 X1=SGN(FNR(X))
219 REM - TEST FOR ROOT AT RANDOM NUMBER; IF YES,  END SEARCH, PRINT
220 IF X1=0 THEN 400
229 REM - TEST FOR OPPOSITE SIGNS AT RANDOM NUMBER AND LOWER LIMIT
230 IF A1*X1<0 THEN 270
239 REM - TRY ANOTHER RANDOM NUMBER
240 NEXT I
250 PRINT "NO CHANGE OF SIGN FOUND"
260 GOTO 60
269 REM - CHANGE OF SIGN FOUND; CALCULATE ROOT
270 B=X
278 REM - STORE POSITIVE POINT IN D(3), NEGATIVE POINT IN D(1)
279 REM - D(3) BECOME INTERVAL LIMITS
280 D(2+A1)=A
290 D(2-A1)=B
299 REM - CALCULATE MIDPOINT BETWEEN THE TWO LIMITS
300 Y=(D(1)+D(3))/2
310 Y1=SGN(FNR(Y))
319 REM - TEST FOR ROOT AT MIDPOINT
320 IF Y1=0 THEN 400
329 REM - GET A NEW LIMIT TO CLOSE IN ON ROOT
330 D(2+Y1)=Y
339 REM - TEST FOR A VALUE CLOSE ENOUGH TO ZERO TO ASSUME A ROOT
340 IF ABS(D(1)-D(3))/ABS(D(1)+ABS(D(3)))<5E-6 THEN 400
349 REM - RETEST WITH NEW LIMITS
350 GOTO 300
359 REM - ROOT AT AN INTERVAL LIMIT; FIND WHICH LIMIT, PRINT
360 IF A1=0 THEN 390
370 Y=B1
380 GOTO 400
390 Y=A1
400 PRINT "ROOT =";Y
410 PRINT
419 REM - RESTART PROGRAM
420 GOTO 60
430 END
