-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsteffensen.sce
49 lines (40 loc) · 961 Bytes
/
steffensen.sce
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
41
42
43
44
45
46
47
48
49
funcprot(0)
function y = f(x)
y = (x^3) -3*x + 2
endfunction
function y = h(x)
y = 3*x^2-3
endfunction
function [p,Q] = steffensen(a, cantIteraciones)
R = zeros(cantIteraciones, 3);
R(1,1) = a;
for k = 1:cantIteraciones
for j = 2:3
nrdenom = h(R(k,j-1));
if nrdenom == 0 then
break;
else
R(k,j)=R(k,j-1)-f(R(k,j-1))/nrdenom;
end
aadenom = R(k,3)-2*R(k,2)+R(k,1);
if aadenom == 0 then
break;
else
R(k+1,1)=R(k,1)-(R(k,2)-R(k,1))^2/aadenom;
end
end
if (nrdenom==0) | (aadenom==0) then
break;
end
p = R(k+1,1);
Q = R(1:k+1,:);
end
endfunction
[p, q] = steffensen(-4, 1)
disp(p)
[p, q] = steffensen(-4, 2)
disp(p)
[p, q] = steffensen(-4, 3)
disp(p)
[p, q] = steffensen(-4, 4)
disp(p)