% plots showing rate of convergence. % % NOTE: if you want to use plots like these in your lab, you % need to explain how they demonstrate rate of convergence. % plot 1 g = inline('sqrt(1+x)'); x = fixed(g, 1, 1e-10, 100); err = log(abs(x - (1 + sqrt(5))/2)); subplot(2,1,1) plot(err, 'ro-'); xlabel('n'); ylabel('log|x_n - \alpha|'); title('linear convergence of x_{n+1} = sqrt(1 + x_n) with x_0 = 1'); % plot 2 g = inline('x/2 + 1/x'); x = fixed(g, 1, 1e-10, 100); err = log(abs(x - sqrt(2))); subplot(2,1,2); k = length(err); plot(2.^(1:k), err, 'ro-'); xlabel('2^n'); ylabel('log | x_n - \alpha |'); title('quadratic convergence of x_{n+1} = x_n/2 + 1/x_n with x_0 = 1');