function out = findpole(gain,range) % initial choise for a value of s pole = mean(range); % initializing delta delta = 1; % limiting number of iterations in case s is not in the range maxiter = 1000; % counting iterations iter = 0; while (delta > 0.01) && (iter < 1000) % enter your system transfer function here sys = (pole+1.5)/(pole*(pole+1)*(pole+10)); % calculates the gain value for the given pole value tmpK = -1/sys; if tmpK > gain range = [min(range), pole]; else range = [max(range), pole]; end % next pole to check pole = mean(range); % different between computed gain vs desired gain delta = abs(gain-tmpK); iter = iter + 1; end if iter == 1000 disp('Desired K is not within range'); out = []; else out = pole; end