How to input a function in matlab? Trying to find roots for any function using newton

I am trying to figure out how I can input a function , find its derivative and evaluate that derivative at a point. Essentially, program Newton's method.
ex.
function y = newton(function,a,b,Nmax, Tol,x0)
yp = deriv(function)
for i 1:Nmax
x1 = function(x0) - function(x0)/yp(x0)
if x1-x0<tol break; end fprintf('root is %d',x1)
But I am not sure how to use a function as an input or how to use the derivative of that function and apply to x0. I just have the general idea.

Answers (0)

Categories

Asked:

on 17 Sep 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!