% script e10plot.m % % this script plots the pairs of functions involved in E10.4 - E10.8 % to show you their behavior as $n$ gets large. % % note the use of log-log axes to accommodate the large range of values: % a constant factor difference 2 functions shows up as % a constant high gap between their graphs help e10plot % print out comments above clear n = 10 .^ round(1:.25:9); figure(4); clf; title('E10.4. O(100 n^2 + 5n + 1) = O(n^2 + 5n + 100)') xlabel('n') loglog(n, 100 * n.^2 + 5*n + 1, 'g*-', n, n.^2 + 5*n + 100, 'bo-'); legend('100 n^2 + 5n + 1','n^2 + 5n + 100') figure(5); clf; title('E10.5. O(10 n^2) < O(2 n^{10})') xlabel('n') loglog(n, 10 * n.^2, 'g*-', n, 2 * n.^10, 'bo-'); legend('10 n^2','2 n^{10}') figure(6); clf; title('E10.6. O(10) = O(1)') xlabel('n') loglog(n, 10*ones(size(n)), 'g*-', n, ones(size(n)), 'bo-'); legend('10','1') figure(7); clf; title('E10.7. O(1 + 1/n) = O(2)') xlabel('n') loglog(n, 1 + 1./n, 'g*-', n, 2*ones(size(n)), 'bo-'); legend('1 + 1/n','2') figure(8); clf; title('E10.8. O(n+log(n)) = O(n)') xlabel('n') loglog(n, n + log(n), 'g*-', n, n, 'bo-'); legend('n + log(n)','n')