This is my code, to find the f(x)=0 positive root, using halleys method

2 m files

1. function file

function [y,dydx,ddyddxx]=h(x)

% The function is expressed, and the 1st and 2nd derivatives are noted

y=exp(cos(x)^2)-x^2;

dydx=-sin(2*x)*exp(cos(x)^2)-2*x;

ddyddxx=2*exp(cos(x)^2)-4*cos(x)^4*exp(cos(x)^2)-2;

end

2. Halleys method

clear all

% clears all the stored variable

format long

%formats the outputs to 10 significant figures

x(1) = 0;

%left bound

x(2) = 1000;

%right bound

eps = 1e-10;

count = 2;

while abs(x(count-1)-x(count)) > eps

% 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)

OK my problem is my initial conditions, as all i have done is put halleys method into newtons method. I need to "using an initial condition value of x1=1000, apply this iterative procedure to f(x) untill |f(xn)|<10^-10 or the number of iterations is 1000, also my program needs to oputput the number of iterations and the root to 10 signif figures. my code has found x to 10 signifs not f(xn) apparently i need to make it like a controlled bisection, and have an || and && statements somewhere... i litterally have no idea how to do this... please can someone help me?