• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Jun 4th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function y = f(x)
2.     y = x**4 + 2*x**3 - 13*x**2 - 14*x + 24;
3. endfunction
4.
5. function s = metodoNewton(x0, Toler, IterMax)
6.     s = zeros(3);
7.     fD = numderivative(f, x0);
8.     Fx = f(x0); DFx = numderivative(f,x0); x = x0; Iter = 0;
9.     printf("%g %g %g %g\n", Iter, x, DFx, Fx);
10.     while(1)
11.         DeltaX = (-1) * Fx/DFx; x = x + DeltaX;
12.         Fx = f(x); DFx = numderivative(f,x);
13.         Iter = Iter + 1;
14.         printf("%g %g %g %g\n", Iter, DFx, Fx, DeltaX);
15.         if( (abs(DeltaX) <= Toler & abs(Fx) <= Toler) | DFx == 0 | Iter >= IterMax)
16.             break;
17.         end
18.     end
19.     Raiz = x;
20.     if(abs(DeltaX) <= Toler & abs(Fx) <= Toler)
21.         CondErro = 0;
22.     else
23.         CondErro = 1;
24.     end
25.
26.     s(1) = Raiz;
27.     s(2) = Iter;
28.     s(3) = CondErro;
29. endfunction
30.
31. x0 = 4;
32. Toler = 1.0000e-05
33. IterMax = 100;
34.
35. disp(metodoNewton(x0,Toler,IterMax));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top