ChipMaster's bwBASIC This also includes history going back to v2.10. *WARN* some binary files might have been corrupted by CRLF.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

72 lines
1.7 KiB

  1. 10 PRINT "REAL ROOTS OF POLYNOMIALS: NEWTON"
  2. 20 PRINT
  3. 28 REM - LIMIT A() AND B() TO N+1; WHEN THIS IS DONE, LOOP AT LINE 40
  4. 29 REM - SHOULD BE SET TO TEST FROM 1 TO N+1
  5. 30 DIM A(11),B(11)
  6. 39 REM - INITIALIZE ARRAY VARIABLES
  7. 40 FOR I=1 TO 11
  8. 50 A(I)=0
  9. 60 B(I)=0
  10. 70 NEXT I
  11. 80 PRINT "DEGREE OF EQUATION";
  12. 90 INPUT N
  13. 100 FOR I=1 TO N+1
  14. 109 REM - ENTER COEFFICIENTS IN ORDER OF LESSER TO HIGHER DEGREE
  15. 110 PRINT "COEFFICIENT A(";I-1;")";
  16. 120 INPUT A(I)
  17. 130 NEXT I
  18. 140 FOR I=1 TO 10
  19. 149 REM - CALCULATE COEFFICIENT OF DERIVATIVE OF POLYNOMIAL
  20. 150 B(I)=A(I+1)*I
  21. 160 NEXT I
  22. 170 PRINT
  23. 179 REM - INITIALIZE GUESS
  24. 180 PRINT "guess";
  25. 190 INPUT X
  26. 200 Q=0
  27. 210 S=1
  28. 220 F1=0
  29. 230 F0=0
  30. 239 REM - COUNT ITERATIONS
  31. 240 Q=Q+1
  32. 250 FOR I=1 TO N+1
  33. 259 REM - CALCULATE VALUE OF FUNCTION
  34. 260 F0=F0+A(I)*S
  35. 269 REM - CALCULATE VALUE OF DERIVATIVE
  36. 270 F1=F1+B(I)*S
  37. 280 S=S*X
  38. 290 NEXT I
  39. 299 REM - TEST FOR A ZERO DERIVATIVE; IF YES, STOP SEARCH, PRINT
  40. 300 IF F1=0 THEN 360
  41. 309 REM - GET NEW GUESS USING PREVIOUS GUESS
  42. 310 S=X-F0/F1
  43. 319 REM - IF NEW GUESS = LAST GUESS THEN STOP SEARCH, PRINT
  44. 320 IF X=S THEN 380
  45. 329 REM - SAVE LAST GUESS
  46. 330 X=S
  47. 340 IF Q>100 THEN 490
  48. 350 GOTO 210
  49. 360 PRINT "DERIVATIVE = 0 AT X =";X
  50. 370 GOTO 180
  51. 380 PRINT
  52. 390 PRINT " ROOT"," ERROR"," DERIVATIVE"
  53. 400 PRINT X,F0,F1
  54. 410 PRINT
  55. 419 REM - RERUN TO FIND ANOTHER ROOT IN SAME FUNCTION?
  56. 420 PRINT "ANOTHER VALUE (1=YES, 0=NO)";
  57. 430 INPUT A
  58. 440 IF A=1 THEN 170
  59. 449 REM - RESTART OR END PROGRAM?
  60. 450 PRINT "ANOTHER FUNCTION (1=YES, 0=NO)";
  61. 460 INPUT A
  62. 470 IF A=1 THEN 30
  63. 480 GOTO 550
  64. 489 REM - PRINT CALCULATE VALUES AFTER 100 ITERATIONS; SEARCH 100 MORE?
  65. 490 PRINT "100 ITERATIONS COMPLETED:"
  66. 500 PRINT " X =";X;" F(x) =";F0
  67. 510 PRINT " CONTINUE (1= YES, 0=NO)";
  68. 520 INPUT A
  69. 530 IF A=1 THEN 200
  70. 540 GOTO 420
  71. 550 END