(f,a,n) which takes three inputs: f: A function handle for a function of x. a: A real number. n: A positive integer. Does n iterations (with a for loop) of the Newton-Raphson method with starting approximation x = a. The initial guess a does not count as an iteration. Returns the nth approximation.
I have:
function r=mynewton(f,a,n) syms x; for i=1:n; x(i+1)=a-f(x(i))/diff(f(x(i))); end; r=x(i+1); end
I know this is incorrect because it will give me the same answer no matter what data I put as f,a or n.
Can anyone help me fix the equation in line 4 or the for loop altogether because i cannot quite get it right.
Best Answer