You are on page 1of 1

7/5/21 3:00 PM Untitled5 1 of 1

syms f(x)
f=symfun(input('f(x)='),x);
x0=input('enter initial value x0:');
t=input('enter the tolarnce(percentage):');
syms f_prime(x)
f_prime=symfun(diff(f),x);
u=x0;
for i=1:100
prev=u;
u=u-eval(f(u)/f_prime(u));
pres=u;
error=abs((pres-prev)/pres)*100;
if error<=t
fprintf('the root is :');
disp(u);
fprintf('iteration number :');
disp(i);
fprintf('error(percentage):');
disp(error);
break
end
if i==100
fprintf('error maximum number of iterations exceeded');
end
end

You might also like