function x = solve_for_x()

% Solve cos(x) = x by solving f(x) = cos(x)-x = 0
f = @(x) cos(x) - x;        % f(x) 
fp  = @(x) -sin(x) - 1;     % f'(x) : Derivative of f(x)

tol = 1e-12;
x(1) = 1;   % Starting guess
kmax = 50;
for k = 1:kmax
   x(k+1) = x(k) - f(x(k))/fp(x(k));  % Iteration
   if abs(x(k+1)-x(k)) < tol
       x = x(:);
       return;
   end
end

x = x(:); % Convert to column vector

end