summaryrefslogtreecommitdiff
path: root/260/CH4/EX4.10/4_10.sce
blob: 255b616399fda7e5000f584f4e1be7a5c493f030 (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
25
26
27
28
29
//Eg-4.10
//pg-161

clear
clc


// Secant Method

A=[-6 5 -3 2];
x1=0.5;
x2=0.7;
eps=10^(-10);
fx=poly(A,'x','c');
iter=1;
Abserr=100;
while Abserr>eps
    printf('iteration number %i\n',iter);
    xnew1=x2-horner(fx,x2)*(x2-x1)/(horner(fx,x2)-horner(fx,x1));
    printf('xnew1 = %f \n',xnew1);
    Abserr = abs(horner(fx,xnew1) - horner(fx,x1))/abs(horner(fx,xnew1));
    x1=x2;
    x2=xnew1;
   iter=iter+1;
end

disp("result was found in iterations")
disp(iter-1)