summaryrefslogtreecommitdiff
path: root/845/CH2/EX2.7/Ex2_7.sce
blob: 43631cc12452ca652fbb4308ddd2edb60fbb6ec8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//Example 2.7
clc
clear

function [f,df] = fun7(x)
    f  = x.*exp(x) - 2;
    df = x.*exp(x) + exp(x);
endfunction

xold = 1;
maxit = 2;
iter = 1;

while (1)
    [fx,dfx] = fun7(xold);
    xnew = xold - fx/dfx;
    if iter == maxit then
        break
    end
    xold = xnew;
    iter = iter + 1;
end
root = round(xnew*10^3) / 10^3;
disp(root,"root = ")