File tree 1 file changed +8
-8
lines changed
1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 2
2
3
3
function y = f (x);
4
4
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)
6
6
endfunction
7
7
8
8
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)
10
10
11
11
// plot da função
12
12
plot(x,f(x), ' -o' );
13
13
xgrid;
14
14
15
- x_velho = 0.01 ; // chute inicial
15
+ x_velho = 0.01 ; // chute inicial (guess)
16
16
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)
18
18
it = 1 ; // iteracão inicial
19
- precisao = -2
19
+ precisao = -2 // (accuracy)
20
20
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
24
24
secante = (f(x_velho)-f(x_velho2))/(x_velho-x_velho2)
25
25
x = x_velho - (f(x_velho)/secante); // calcular o proximo x
26
26
erro = abs((x-x_velho)/ x);
You can’t perform that action at this time.
0 commit comments