Skip to content

Commit dfbb4ba

Browse files
authored
Update and rename Método da Bisseção.sce to bissection-method.sce
1 parent 6ab41c6 commit dfbb4ba

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

Método da Bisseção.sce

-34
This file was deleted.

bissection-method.sce

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//Bolzano method by Rêmullo Costa
2+
function y = f(x)
3+
y = x^3-5*x+1;
4+
endfunction
5+
6+
x = 0:0.1:3;
7+
y = f(x);
8+
9+
plot(x,y);
10+
xgrid;
11+
12+
a = 0.1; //ponto a avaliado por visualização grafica (point 'a' evaluated by graphical visualization)
13+
b = 0.3; // ponto b avaliado por visualização grafica (point 'b' evaluated by graphical visualization)
14+
x = a; //chute inicial (guess)
15+
erro = 1; //erro inicial (1st error value)
16+
iter = 1;
17+
=
18+
while(erro > 10^-2) //A condição de parada é quando o erro for menor que 10ˆ-2 (stop condition is when the error is smaller than 10^-2)
19+
x_velho = x; //this variable saves the latest 'x', because it will be modified
20+
x = (a+b)/2;
21+
//Teorema de Bolzano
22+
if(f(a)*f(x)<0) then // se a raiz tiver entre a e x, entao x será o novo b (if the found root is between 'a' and 'x', thus, 'x' will be the new 'b'
23+
b = x;
24+
elseif(f(b)*f(x)<0) then //se a raiz estiver entre "b e x", então "x" será o novo a (if the root is in between of 'b' and 'x', then 'x' will be the new 'a'
25+
a = x;
26+
end
27+
28+
//avaliar o erro no fim do loop para ver se a condição foi satisfeita (evaluate the error in the end of the loop to check if the condition were satisfied)
29+
erro = abs((x - x_velho)/x);
30+
disp([iter x erro]);
31+
iter = iter +1;
32+
33+
end
34+

0 commit comments

Comments
 (0)