My code works BUT I need to add 2 more things:
- output- a vector containing the sequence of estimates including the initial guess x0,
-
input- max iterations
function [ R, E ] = myNewton( f,df,x0,tol ) i = 1; while abs(f(x0)) >= tol R(i) = x0; E(i) = abs(f(x0)); i = i+1; x0 = x0 - f(x0)/df(x0); end if abs(f(x0)) < tol R(i) = x0; E(i) = abs(f(x0)); end end
well, everything you need is pretty much done already and you should be able to deal with it, btw..
max iteration is contained in the variable
i, thus you need to return it; add thisPlot sequence of estimates:
display max number of iterations