blob: d35f210b4624ff3f3f221e3692cef966a08eae1f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
function x=newton4(x,f,fp)
R=4;
PE=10^-15;
maxval=10^4;
for n=1:1:R
if fp(x)==0 then disp("select another initial root x0")
end
x=x-f(x)/fp(x);
if abs(f(x))<=PE then break
end
if (abs(f(x))>maxval) then error('Solution diverges');
abort
break
end
end
disp(n," no. of iterations =")
endfunction
|