-
Notifications
You must be signed in to change notification settings - Fork 0
/
Phase.m
92 lines (85 loc) · 2.12 KB
/
Phase.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
classdef Phase < handle
properties(SetAccess=immutable)
K
M
D
N
weights
nodes
Nstate
Ncontrol
Npath
end
properties
state
control
bounds
dynamics
path
guess
tfidx
t0idx
auxdata
end
methods
function obj = Phase(varargin)
p = inputParser;
p.addParameter('K', 0, @(x) (x == floor(x) && x > 0));
p.addParameter('M', 0, @(x) (x == floor(x) && x > 0));
p.addParameter('Nstate', 0, @(x) (x == floor(x) && x >= 0));
p.addParameter('Ncontrol', 0, @(x) (x == floor(x) && x >= 0));
p.addParameter('Npath', 0, @(x) (x == floor(x) && x >= 0));
p.parse(varargin{:});
fn = fieldnames(p.Results);
for k = 1:numel(fn)
eval(sprintf('obj.%s = %d;', fn{k}, p.Results.(fn{k})));
end
%[ obj.D, obj.nodes, obj.weights, obj.N ] = d_matrix2(obj.M, obj.K, 2);
[ obj.D, obj.nodes, obj.weights, obj.N ] = d_matrix(obj.M, obj.K);
state = Variable.empty
for i = 1:obj.Nstate
state(i) = Variable(obj.N);
end
control = Variable.empty
for i = 1:obj.Ncontrol
control(i) = Variable(obj.N);
end
obj.state = state;
obj.control = control;
end
function guess_api(obj, what, val)
switch what
case 'constant_control'
if length(val) ~= obj.Ncontrol
error( "bad length" );
end
for i = 1:obj.Ncontrol
obj.control(i).constant_guess(val(i))
end
case 'constant_state'
if length(val) ~= obj.Nstate
error( "bad length" );
end
for i = 1:obj.Nstate
obj.state(i).constant_guess(val(i))
end
case 'time'
if length(val) ~= 2
error( "bad length" );
end
obj.guess.time = val';
otherwise
error( sprintf("unknown option %s", what) );
end
end
end
methods(Static)
function phases = PhaseArray(n, varargin)
for i = 1:n
phases(i) = Phase(varargin{:});
end
end
function phases = PhasesFromStages(stages)
end
end
end