-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpacecraftStochastic.m
59 lines (51 loc) · 1.6 KB
/
SpacecraftStochastic.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
classdef SpacecraftStochastic < Spacecraft
properties
Cn; % Cx's names
mean;
end
properties (Access = protected)
idx;
end
properties (Access = protected, Constant)
sorted = {'CL', 'CD', {'Cm', 'CmAft'}, 'Cmq'}; % possible coefficient names in order of priority
end
methods
% Constructor
function self = SpacecraftStochastic(sc, inputs, Ms, Kns)
% sc := Spacecraft object (non-Stochastic)
self = self.copy(sc); % @Spacecraft(sc);
% Get available coefficients
allCn = fieldnames(self.db);
self.Cn = cell(1, numel(inputs));
if nargin == 2
self.idx = find(self.db.alpha);
elseif nargin == 4
self.idx = find((self.db.M >= Ms(1) & self.db.M <= Ms(2)) & (self.db.Kn >= Kns(1) & self.db.Kn <= Kns(2)));
else
util.exception('Expected either 2 or 4 input arguments');
end
% Save coefficient names and their mean values
for i = 1:numel(inputs)
self.Cn{i} = cell2mat(intersect(self.sorted{i}, allCn));
self.mean.(self.Cn{i}) = self.db.(self.Cn{i});
end
end
function update(self, Y)
% Add random noise to first N Cx's: CL, CD, Cm, ...
% but only to the corresponding indices
for i = 1:numel(Y)
self.db.(self.Cn{i})(self.idx) = self.mean.(self.Cn{i})(self.idx) * Y(i);
self.F.(self.Cn{i}) = griddedInterpolant(self.db.alpha, self.db.M, self.db.Kn, self.db.(self.Cn{i}));
end
end
end
methods (Access = protected)
function self = copy(self, obj)
for pr = metaclass(self).PropertyList.'
if isprop(obj, pr.Name) && ismember(pr.SetAccess, {'public', 'protected'})
self.(pr.Name) = obj.(pr.Name);
end
end
end
end
end