|
- 10 PRINT "REAL ROOTS OF POLYNOMIALS: NEWTON"
- 20 PRINT
- 28 REM - LIMIT A() AND B() TO N+1; WHEN THIS IS DONE, LOOP AT LINE 40
- 29 REM - SHOULD BE SET TO TEST FROM 1 TO N+1
- 30 DIM A(11),B(11)
- 39 REM - INITIALIZE ARRAY VARIABLES
- 40 FOR I=1 TO 11
- 50 A(I)=0
- 60 B(I)=0
- 70 NEXT I
- 80 PRINT "DEGREE OF EQUATION";
- 90 INPUT N
- 100 FOR I=1 TO N+1
- 109 REM - ENTER COEFFICIENTS IN ORDER OF LESSER TO HIGHER DEGREE
- 110 PRINT "COEFFICIENT A(";I-1;")";
- 120 INPUT A(I)
- 130 NEXT I
- 140 FOR I=1 TO 10
- 149 REM - CALCULATE COEFFICIENT OF DERIVATIVE OF POLYNOMIAL
- 150 B(I)=A(I+1)*I
- 160 NEXT I
- 170 PRINT
- 179 REM - INITIALIZE GUESS
- 180 PRINT "guess";
- 190 INPUT X
- 200 Q=0
- 210 S=1
- 220 F1=0
- 230 F0=0
- 239 REM - COUNT ITERATIONS
- 240 Q=Q+1
- 250 FOR I=1 TO N+1
- 259 REM - CALCULATE VALUE OF FUNCTION
- 260 F0=F0+A(I)*S
- 269 REM - CALCULATE VALUE OF DERIVATIVE
- 270 F1=F1+B(I)*S
- 280 S=S*X
- 290 NEXT I
- 299 REM - TEST FOR A ZERO DERIVATIVE; IF YES, STOP SEARCH, PRINT
- 300 IF F1=0 THEN 360
- 309 REM - GET NEW GUESS USING PREVIOUS GUESS
- 310 S=X-F0/F1
- 319 REM - IF NEW GUESS = LAST GUESS THEN STOP SEARCH, PRINT
- 320 IF X=S THEN 380
- 329 REM - SAVE LAST GUESS
- 330 X=S
- 340 IF Q>100 THEN 490
- 350 GOTO 210
- 360 PRINT "DERIVATIVE = 0 AT X =";X
- 370 GOTO 180
- 380 PRINT
- 390 PRINT " ROOT"," ERROR"," DERIVATIVE"
- 400 PRINT X,F0,F1
- 410 PRINT
- 419 REM - RERUN TO FIND ANOTHER ROOT IN SAME FUNCTION?
- 420 PRINT "ANOTHER VALUE (1=YES, 0=NO)";
- 430 INPUT A
- 440 IF A=1 THEN 170
- 449 REM - RESTART OR END PROGRAM?
- 450 PRINT "ANOTHER FUNCTION (1=YES, 0=NO)";
- 460 INPUT A
- 470 IF A=1 THEN 30
- 480 GOTO 550
- 489 REM - PRINT CALCULATE VALUES AFTER 100 ITERATIONS; SEARCH 100 MORE?
- 490 PRINT "100 ITERATIONS COMPLETED:"
- 500 PRINT " X =";X;" F(x) =";F0
- 510 PRINT " CONTINUE (1= YES, 0=NO)";
- 520 INPUT A
- 530 IF A=1 THEN 200
- 540 GOTO 420
- 550 END
|