Assuming your code for Halley's method is correct:

Code:

clear all % clears all the stored variable
format long %formats the outputs to 10 significant figures
x=zeros(1,1000);
x(1) = 1;
[y,dydx,ddyddxx]= h(x(1));
eps = 1e-10;
count = 1;
while (abs(y) > eps) && (count<=1000)
% calculating the derivatives
[y,dydx,ddyddxx]= h(x(count));
x(count+1) = x(count) - ((y*dydx)/(((dydx)^2)-(ddyddxx*y)/2));
fprintf('The root is approximately %1.10f\n',x(count+1));
count = count + 1;
end
fprintf('The solution of exp(cos(x)^2)-x^2 is approximately %1.10f\nThis algorithm took %u iterations to complete\n',x(count),count-2)

Note the initial guess should be near the root.

CB