clear format compact format long x1 = .01; x = newton(@f, @dfdx, x1, 20); length(x) function y = f(x) % F demonstrate the case of no-convergence for Newton's method if x > 0 y = sqrt(x); else y = -sqrt(-x); end end function y = dfdx(x) % DFDX demonstrate the case of no-convergence for Newton's method if x > 0 y = 1/(2*sqrt(x)); elseif x < 0 y = 1/(2*sqrt(-x)); else y = 0; end end