• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jun 4th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.
2. function s = f(x)
3.     s = 2*x**3 - cos(x+1) - 3;
4. endfunction
5.
6. function s = metodoPegaso(a, b, Toler, IterMax)
8.     // a = lim Inf
9.     // b = lim Sup
10.     s = zeros(3);
11.
12.     Fa = f(a); Fb = f(b);
13.     x = b; Fx = Fb; Iter = 0;
14.     while(1)
15.         DeltaX = (-1)*Fx/(Fb - Fa)*(b-a);
16.         x = x + DeltaX; Fx = f(x);
17.         printf("%g  %.4g  %.4g  %.4g  %.4g  %.4g  %.4g \n", a, Fa, b, Fb, x, Fx, DeltaX);
18.         if( ( abs(DeltaX) <= Toler & abs(Fx) <= Toler ) | (Iter >= IterMax) )
19.             break;
20.         end
21.         if( Fx * Fb < 0 )
22.             a = b; Fa = Fb;
23.         else
24.             Fa = Fa * Fb/(Fb + Fx);
25.         end
26.
27.         b = x; Fb = Fx;
28.         Iter = Iter + 1;
29.     end
30.     Raiz = x;
31.     if(abs(DeltaX) <= Toler & abs(Fx) <= Toler)
32.         CondErro = 0;
33.     else
34.         CondErro = 1;
35.     end
36.     // Saida
37.     s(1) = Raiz;
38.     s(2) = Iter;
39.     s(3) = CondErro;
40. endfunction
41.
42. a = -1;
43. b = 2;
44. Toler = 0.01;
45. IterMax = 100;
46. disp(metodoPegaso(a,b,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.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top