clear all
clc
format long

syms x

prompt = 'Function: ';
f = input(prompt);
prompt = 'x0: ';
a = input(prompt);
prompt = 'Number of Iterations: ';
k = input(prompt);

d_f = diff(f);
z =1:k+1;
z(1) = a;

for i = 1: 1: k
    z(i+1) = z(i) - (subs(f,x,vpa(z(i)))/subs(d_f,x,vpa(z(i))));
    erro = abs(z(i+1)-z(i));
end

r=z(i+1);
display(r)
display(erro)
