DECLARE FUNCTION Funct! (x!) DECLARE SUB Improve (x!) CLS PRINT "Demonstration of Blind search for max of Funct(x)" PRINT PRINT "Current best values" PRINT "x", "max", "found in trial #" xb = 0 'initial guess FM = Funct(0) DO 'tell user what is going on ct = ct + 1 LOCATE 10, 10 PRINT "Trying #"; ct 'try a random modification of XB x = xb CALL Improve(x) 'this just randomizes 'compute value F = Funct(x) IF F >= FM THEN ' found better xb, so memorize it xb = x FM = F LOCATE 5, 1 PRINT SPACE$(79) LOCATE 5, 1 PRINT x, F, ct END IF LOOP FUNCTION Funct (x) 'put any expression here, including IF...THEN, calls to other SUBs, etc. '(things get more exciting with more arguments!) Funct = 300 * EXP(-(x - 20) ^ 2 / 50) * SIN(20 * x) END FUNCTION SUB Improve (x) 'get something random near x 'if x is of limited range, check if correct here RANDOMIZE TIMER x = x + LOG(RND(1) / RND(1)) END SUB