-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFixpoint.m
72 lines (59 loc) · 1.71 KB
/
Fixpoint.m
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
classdef Fixpoint
% Fixpoint Fixed-Point Iteration
% H = Fixpoint creates an object which computes approxmate solution
% of f(x)=x using Fixed-Point Iteration.
%
%% Input Properties
properties
% Func Function f(x) (Function handle)
% the default is cos(x)
Func = @(x) cos(x);
% Step Number of iteration steps (Scalar)
% the default value is 30
Step = 30;
% IniX Initial guess (Scalar)
% the default value is 1
IniX = 1;
end
%% Output Properties
properties( Dependent = true , SetAccess = private )
% Y Approxmate solution of f(x)=x
% the default value is 0.7391
Y = 0.7391;
end
%% Set Properties to Specific Values
methods
function obj = set.Func(obj,value)
obj.Func = value;
end
function obj = set.Step(obj,value)
obj.Step = value;
end
function obj = set.IniX(obj,value)
obj.IniX = value;
end
end
%% Fixed-Point Iteration
methods
function Y = get.Y(obj)
f = obj.Func;
x = zeros(1,obj.Step+1);
x(1) = obj.IniX;
for i = 1:obj.Step
x(i+1) = f(x(i));
end
Y = x(obj.Step+1);
end
end
%% Constructor
methods
function obj = Fixpoint(func,inix,step)
if nargin == 0
else
obj.Func = func;
obj.IniX = inix;
obj.Step = step;
end
end
end
end %EoC