"code never uses indicated local function" error?
조회 수: 3 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
madhan ravi
2018년 11월 27일
root = Newton(x0,tol,MaxIter) %this line have to be before the function root...
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!