Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function x=newtonTest(f,x)
- xprev = x-1;
- df=@(x,h)(f(x+h)-f(x-h))./(2*h); % df(x,h) ~ f'(x)
- h = 0.0001; %bardzo mala liczba
- epsilon0 = 0.001; % wartosc od ktorej dana wartosc zaczyna byc postrzegana jako 0
- epsilonDif = 0.001; %roznica od ktorej dwie wartosci zaczynaja byc postrzegane jako rowne, musi byc <1
- maxIterations = 100;
- while abs(f(x))> epsilon0 && abs(x-xprev)>epsilonDif && maxIterations>0
- % disp(maxIterations);
- d = df(x,h);
- if abs(d) < epsilon0 % f'(x) = 0
- error('Niespelniono warunku: f''(x) != w calym przedziale');
- end
- xprev = x;
- x = x-f(x)/d;
- maxIterations = maxIterations-1;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement