"code never uses indicated local function" error?
Show older comments
This is my code for a class project:
x0 = 0.5;
tol = 0.00000005;
MaxIter = 20;
syms f(x)
f(x) = piecewise(x>=0,sqrt(x),x<0,-sqrt(-x));
function root = Newton(x0,tol,MaxIter)
format short e
error = 1;
it_count = 0;
fprintf('\n it_count x f(x) df(x) error \n')
while abs(error) > tol && it_count < MaxIter
fx = f(x0);
dfx = deriv_f(x0);
if df == 0
disp('The derivative is zero, stop')
return
end
x1 = x0 - fx/dfx;
error = x1 - x0;
x0 = x1;
it_count = it_count + 1;
end
if it_count >= MaxIter
disp('number iterates exceeded MaxIter, no accurate root found')
else
format long
root = x1
format short
end
end
For some reason I keep getting an error that says the local funciton "Newton" is unused. Honestly I'm not well-versed in Matlab, so I'm just working from a template so I don't understand how that function is unused. What do I do here?
Answers (1)
madhan ravi
on 27 Nov 2018
root = Newton(x0,tol,MaxIter) %this line have to be before the function root...
Categories
Find more on Image Thresholding 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!