Labreport Module 4 - Maglinte
Labreport Module 4 - Maglinte
A. Objectives
b. To know how to solve the roots of nonlinear equations using the GNU
Octave.
Bisection Method
Regula Falsi Method
Newton Raphson Method
Secant Method
Fixed Point Method
C. Output
Bisection Method
for i = 1:imax
xNS = (a + b)/2;
toli = (b - a)/2;
FxNS = F(xNS);
if FxNS == 0
fprintf('An exact solution x = %11.6f was not found', xNS)
break
end
break
end
if 1 == imax
fprintf('Solution was not obtained in %i iterations', imax)
break
end
else
a = xNS;
end
end
end
iteration a b (xNS)
Solution f(xNS) Tolerance
xNS = 0.85254
for i = 1:imax
xNS = ((a*Fb)-(b*Fa))/(Fb-Fa);
erro = (b - a)/ b;
FxNS = F (xNS);
break
end
break
end
if i == imax
fprintf('Solution was not obtained in %i iterations' , imax)
break
end
if F(a)*FxNS < 0
b = xNS;
else
a = xNS;
end
end
End
iteration a b (xNS)
Solution F(xNS) Error
%F(X)
y1 = Xest - 2 * e^(-Xest);
%CALCULATION OF ERROR
Error = abs((Xi - Xest)/Xest);
%DISPLAY ANSWER
fprintf('%i %.6f %.6f %.6f \n', i, Xest, Xi, Error)
break
end
%ITERATION LIMIT
if i == imax
fprintf(' Solution wasn not obtained in %i iterations. \n', imax)
Xs = (' No answer');
end
i = i;
Xest = Xi;
End
Secant Method
>> % Determine the root of f(x) = x-2e^(-x) with Secant Method
>>
>> %Initial Condition
>> Xa = 0;
>> Xb = 1;
>>
>> % setting of parameters
>> Err = 0.000001;
>> imax = 10;
>> format long
>>
>> %display header
>> fprintf(' i Xa Xb Error \n')
i Xa Xb Error
>>
>> %Main Code
>> for i = 1:imax
%f(Xb)
yXb = Xb - 2 * e^(-Xb);
%f(Xa)
yXa = Xa - 2 * e^(-Xa);
%calculation of error
Error = abs((Xi - Xb) / Xb);
%display answer
fprintf (' %i %.6f %.6f %.6f \n', i, Xa, Xb, Error)
%Calculation of error
if abs ((Xi - Xb) / Xb) <Err
Xs = Xi
break
end
i = i;
Xa = Xb;
Xb = Xi;
End
%f(x)
Xi = 2*e^(-Xest);
%calculation of error
Error = abs ((Xi - Xest) / Xest);
%display answer
fprintf (' %i %.6f %.6f %.6f \n', i, Xest, Xi, Error)
break
end
i = i;
Xest = Xi;
end
1 1.000000 0.735759 0.264241
2 0.735759 0.958283 0.302442
3 0.958283 0.767101 0.199505
4 0.767101 0.928714 0.210680
5 0.928714 0.790123 0.149229
6 0.790123 0.907578 0.148655
7 0.907578 0.807000 0.110820
8 0.807000 0.892389 0.105810
9 0.892389 0.819352 0.081844
10 0.819352 0.881434 0.075770
11 0.881434 0.828377 0.060195
12 0.828377 0.873515 0.054490
13 0.873515 0.834963 0.044135
14 0.834963 0.867781 0.039305
15 0.867781 0.839764 0.032286
16 0.839764 0.863625 0.028413
17 0.863625 0.843262 0.023578
18 0.843262 0.860609 0.020571
19 0.860609 0.845809 0.017197
20 0.845809 0.858420 0.014910
D. Conclusion