Newtons Method (Receiving multiple errors)

14 views (last 30 days)
function root = newtons(fun,dfun,x0)
format long
x = fzero(fun,x0);
xi = x0;
count = 0;
fprintf('The MATLAB approximation of the real zero of the function is %s\n',x)
while abs(xi - x) > 10^(-12)
xj = xi - ((fun(xi))/(dfun(xi)));
xi = xj;
count = count + 1;
end
fprintf('Number of iterations: %s \n',count)
root = xi;
end
I am trying to perform the newtons method and have been receiving this error in my code when i try to run "root = newtons(fun,dfun,0.5)" in my livescript. I could really use some help as this is beginning to drive me crazy and im not sure what is wrong with my code. My project is asking for the amount of iterations and the original approximation.

Answers (0)

Categories

Find more on Software Development Tools in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!