-
Notifications
You must be signed in to change notification settings - Fork 1
/
teste_fminsearch.m
49 lines (42 loc) · 1.11 KB
/
teste_fminsearch.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
global venus_swing_by
venus_swing_by = 1;
opts = optimset(...
'TolFun', 1e-14,...
'TolX', 1e-14,...
'MaxFunEvals', 1e4,...
'MaxIter', 1e4...
);
itr = 0;
while itr < 10
itr = itr + 1;
x0 = random_uniform(lower_boundary, upper_boundary);
x = fminsearch(@custo, x0, opts);
disp("Iteração: " + itr);
disp(x);
disp("Custo: " + custo(x));
%% Storage
% Create a table with the data and variable names to store
data_to_store = [
custo(x), ...
x(:)' ...
];
T_to_append = array2table(...
data_to_store...
);
%% Load current existing data
if venus_swing_by == 1
data_title = "-swing-by";
else
data_title = "-direct-transfer";
end
output_file_name = "results_fminsearch" + data_title + ".txt";
if exist('T_fminsearch','var') == 1
T_fminsearch = [T_fminsearch; T_to_append];
elseif exist(output_file_name, 'file') == 2
T_fminsearch = readtable(output_file_name);
else
T_fminsearch = T_to_append;
end
%% Write data to text file
writetable(T_fminsearch, output_file_name);
end