Skip to content

Commit ec0100d

Browse files
authored
Update and rename Método da Secante.sci to secant-method.sci
1 parent dfbb4ba commit ec0100d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Método da Secante.sci secant-method.sci

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
function y = f(x);
44
p = 3.5;
5-
y = (x ./ (1-x)) .* sqrt(2 * p./(2 + x)) - 0.04; //função a ser utilizada
5+
y = (x ./ (1-x)) .* sqrt(2 * p./(2 + x)) - 0.04; //função a ser utilizada (fuction to be used - can be any function)
66
endfunction
77

88

9-
x = [0:0.01:0.1]; //valores de x para checar a função no gráfico
9+
x = [0:0.01:0.1]; //valores de x para checar a função no gráfico (velues of 'x' to check the function on the graphic)
1010

1111
//plot da função
1212
plot(x,f(x), '-o');
1313
xgrid;
1414

15-
x_velho = 0.01; //chute inicial
15+
x_velho = 0.01; //chute inicial (guess)
1616
x = 0.1;
17-
erro = 1; //erro inicial para rodar a função
17+
erro = 1; //erro inicial para rodar a função (initial error to run the function)
1818
it = 1; //iteracão inicial
19-
precisao = -2
19+
precisao = -2 //(accuracy)
2020

21-
while(erro >= 10^precisao)&it<200 do
22-
x_velho2 = x_velho;
23-
x_velho = x;
21+
while(erro >= 10^precisao)&it<200 do //if the error is bigger than the accuracy and the iteration is smaller than 200
22+
x_velho2 = x_velho; //save the first initial guess
23+
x_velho = x; //change the initial guess for x
2424
secante = (f(x_velho)-f(x_velho2))/(x_velho-x_velho2)
2525
x = x_velho - (f(x_velho)/secante); //calcular o proximo x
2626
erro = abs((x-x_velho)/ x);

0 commit comments

Comments
 (0)