summaryrefslogtreecommitdiff
path: root/260/CH4/EX4.2/4_2.sce
blob: 4b0c67a63828e3d63d0d27872e4ceb033fa050a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//Eg-4.2
//pg-143

clear
clc

xl=0;
xu=1;
for i=1:20
    fl=xl-cos(xl);
    fu=xu-cos(xu);
    rt=(xl+xu)/2;
    fr=rt-cos(rt);
    if fl*fr<0 then
        xu=(xl+xu)/2;
    elseif fr*fu<0 then
        xl=(xl+xu)/2;
    else
        rt=(xl+xu)/2; 
    end
   
end
printf('The solution after 20 iterations is %f',rt)