function [root guesses] = directedRandSqrt( n, epsilon ) guess = 1; guesses = [ guess ]; lower = 0; upper = n; while abs(guess*guess - n) > epsilon % to improve my guess, I want to change lower and uppper bounds, and have a guess between lower and % upper % check if the guess is a lower or upper bound if guess*guess < n lower = guess; else %guess*guess >= n upper = guess; end %Make a new guess range = upper - lower; guess = rand()*range + lower; guesses = [guesses guess]; end root = guess; end