clear format compact format long x1 = .01; x = newton(@f, @dfdx, x1, 20); number_of_iterations = length(x) np = 100; t1 = linspace(-10*x1, 10*x1, np); figure(1) plot(t1, f(t1), '-') grid on t2 = logspace(-3, 3, np); figure(2) semilogx(t2, f(t2), '-') grid on hold on for i = 1:length(x) semilogx(x(i), f(x(i)), 'x') end function y = f(x) % F demonstrate the case of divergence for Newton's method alpha = 0.009; y = x./(alpha^2 + x.^2); end function y = dfdx(x) % DFDX demonstrate the case of divergence for Newton's method alpha = 0.009; y = (alpha^2 - x^2)/(alpha^2 + x^2)^2; end