Task

Create a program that finds and outputs the roots of a given function, range and (if applicable) step width.

The program should identify whether the root is exact or approximate.



For this task, use:      ƒ(x)   =   x3 - 3x2 + 2x 

      function$ = "x^3-3*x^2+2*x"
      rangemin = -1
      rangemax = 3
      stepsize = 0.001
      accuracy = 1E-8
      PROCroots(function$, rangemin, rangemax, stepsize, accuracy)
      END
 
      DEF PROCroots(func$, min, max, inc, eps)
      LOCAL x, sign%, oldsign%
      oldsign% = 0
      FOR x = min TO max STEP inc
        sign% = SGN(EVAL(func$))
        IF sign% = 0 THEN
          PRINT "Root found at x = "; x
          sign% = -oldsign%
        ELSE IF sign% <> oldsign% AND oldsign% <> 0 THEN
            IF inc < eps THEN
              PRINT "Root found near x = "; x
            ELSE
              PROCroots(func$, x-inc, x+inc/8, inc/8, eps)
            ENDIF
          ENDIF
        ENDIF
        oldsign% = sign%
      NEXT x
      ENDPROC