summaryrefslogtreecommitdiff
path: root/191/CH3/EX3.3/Example3_3.sce
blob: 0cd02ef2658d0431087a4e5d2875e85121fb10c5 (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
30
31
32
33
34
35
36
37
38
39
40
//We have quadratic equation x^2-2*x-8=0 with roots -2 and 4
//for solving it we use fixed point iteration method for that we rearrange it in 3 ways.
//first way x=(2*x+8)^(1/2)
//here x0 is chosen arbitrarily

clear;
clc;
close();
format('v',5)
funcprot(0);
deff('[fixed_point]=fx(x)','fixed_point=(2*x+8)^0.5')
x0=5;
while abs(x0-fx(x0))>0.5*10^(-2)
  x0=fx(x0);
end
disp(x0,'root is :')

//second way x=(2*x+8)/x

format('v',5)
funcprot(0);
deff('[fixed_point]=fx(x)','fixed_point=(2*x+8)/x')
x0=5;
while abs(x0-fx(x0))>0.5*10^(-2)
  x0=fx(x0);
end
disp(x0,'root is :')

//third way x=(x^2-8)/2

format('v',10)
funcprot(0);
deff('[fixed_point]=fx(x)','fixed_point=(x^2-8)/2')
x0=5;
for i=1:5
  x0=fx(x0);
  disp(x0,'value is :')
end
disp(x0,'As you can see that the root is not converging.So this method is not applicable.')