blob: e6b8f27e36cf96c6b3bec7a3ed9a5bafc5bc271c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
//Example 2.6
clc
clear
function f = fun6(x)
f = 1./ sqrt(x+1);
endfunction
tol = 1e-4;
maxit = 6;
xold = 1;
iter = 1;
while(1)
xnew = fun6(xold);
EA = abs(xnew - xold);
if EA < tol | iter > maxit then
break
end
xold = xnew;
iter = iter + 1;
end
root = round(xnew*10^4) / 10^4; //rounded to 4 decimal places
disp(root,"root = ")
|