Newton's method is an iterative numerical method for finding the roots of a function. In matlab, we can implement Newton's method as follows:
main.m628 chars24 linesThe inputs to the newton function are:
f: matlab function handle for the function to find roots ofdf: matlab function handle for the first derivative of fx0: initial guess for roottol: tolerance for stopping criterion (e.g. 1e-6)maxit: maximum number of iterations to run (e.g. 100)The function outputs the approximation of the root and the number of iterations required.
To use the newton function, you can define an anonymous function for f and df (or use pre-defined functions), call the newton function with your inputs, and print the results:
main.m258 chars11 lines
gistlibby LogSnag