-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOptimizeNonlinear.m
More file actions
91 lines (56 loc) · 1.97 KB
/
Copy pathOptimizeNonlinear.m
File metadata and controls
91 lines (56 loc) · 1.97 KB
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
function [uOptReshape, rMax] = OptimizeNonlinear()
%OptimizeLinear Performs nonlinear optimization of the constellation
%separation problem
% Performs nonlinear optimization of the constellation separation problem
%% Import global variables
global Amin;
global Amax;
global N;
global dt;
global D;
global delta_des;
global epsTheta;
global epsOmega;
global re;
global T;
global r0;
global w0;
global theta0;
%% Create cost function
f = [zeros(1,N*T), 1];
x0 = [repmat(Amin+0.01, N*T, 1); -(475e3+re)]; % Initial guess
costfun = @(x)f*x;
%Create (highly) nonlinear constraint function
function [c, ceq] = nonlcon(x)
t = x(end);
%Reshape x into form suitable for computing trajectory
u = reshape(x(1:end-1), T, N);
u = u';
%Calculate state at time T
[r, w, theta] = trajectory(u);
rT = r(:,end);
wT = w(:,end);
thetaT = theta(:,end);
%Compute constraints on r, theta, and w
rConst = -rT - t*ones(N,1);
thetaConst = max(abs(D*thetaT - delta_des)) - epsTheta;
wConst = max(abs(D*wT)) - epsOmega;
c = [rConst; thetaConst; wConst];
ceq = [];
end
%Formulate other constraints, mostly empty
A = [];
b = [];
Aeq = [];
beq = [];
lb = [repmat(Amin, N*T, 1); -Inf];
ub = [repmat(Amax, N*T, 1); Inf];
% Perform optimization. NOTE: for final results, disable parallelization
options = optimoptions('fmincon', 'Display', 'iter', 'MaxFunctionEvaluations', 1000*N*T, 'UseParallel', false);
result = fmincon(costfun, x0, A, b, Aeq, beq, lb, ub, @nonlcon, options);
uOpt = result(1:end-1); % Extract area commands
thresh = result(end); % Extract radius
uOptReshape = reshape(uOpt, T, N);
uOptReshape = uOptReshape';
rMax = -thresh; % Determines maximized radius
end