I've been using this for a Newton Approximation in Matlab(adsbygoogle = window.adsbygoogle || []).push({});

function x = Newton(f, fp, x, nmax, e)

% f is an inline function which we apply Newton's method on

% fp is an inline function that is the derivative of function f

% x is the initial guess of the root

% nmax is the total number of iterations done

% e is the error used to control convergence

fprintf('x(0) = %10g \n', x)

for n = 1:nmax

d = f(x)/fp(x);

x = x - d;

fprintf('x(%i) = %10g \n', n, x)

if abs(d) < e

fprintf('Converged! \n')

return

end

end

with this to run it:

%declare our function f

f = inline('e^x+2^(-1*x)+2*cos(x)-6');

% declare the derivative of function f

fp = inline('e^x-ln(2)*2^(-1*x)-2*sin(x)');

% declare total number of iterations to be undertaken

nmax = 100;

% declare value of initial starting point

x = 1.0;

% declare amount of error allowed

e = 10.0e-5;

% carry out iteration using function above

x = newton2(f,fp,x,nmax,e);

This isn't working or running for this function, but has run fine for every other function. I'm not sure what isn't working about it. I keep getting the error:

Error using inline/subsref (line 13)

Not enough inputs to inline function.

Error in newton2 (line 11)

d = f(x)/fp(x);

But I am very new to Matlab, and have no idea what this means.

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Newton's Method Matlab Code

Loading...

Similar Threads - Newton's Method Matlab | Date |
---|---|

Using Newton Raphson for Root Finding and Parameters' Estimation | Jun 25, 2014 |

Newton's Method In Matlab | Oct 14, 2013 |

Matlab Newton-Raphsons method | Oct 12, 2012 |

Code for 2 dimesional newtons method. | Mar 5, 2012 |

Matlab, iteration with newton's method, noobs & errors | Apr 2, 2008 |

**Physics Forums - The Fusion of Science and Community**