-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimise_weights.m
executable file
·50 lines (40 loc) · 1.36 KB
/
optimise_weights.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
%iterative optimization of bernstein weights
function[bPoly]= optimise_weights(bPoly, bounds)
import bernsteinPoly.*;
import optimizeBernstein.*;
optbPoly = generalizedoptimizeBernstein;
optbPoly.bPoly = bPoly;
optbPoly.xc = bPoly.X(2:end-1);
optbPoly.yc = bPoly.Y(2:end-1);
optbPoly.tc = bPoly.tc(2:end-1);
optbPoly.x0 = bPoly.X(1);
optbPoly.y0 = bPoly.Y(1);
optbPoly.xf = bPoly.X(end);
optbPoly.yf = bPoly.Y(end);
if isfield(bounds,'xdoteq')
optbPoly.xdoteq = bounds.xdoteq ;
optbPoly.ydoteq = bounds.ydoteq ;
end
if isfield(bounds,'xdotmax')
optbPoly.xdotmax = bounds.xdotmax;
optbPoly.ydotmax = bounds.ydotmax;
end
if isfield(bounds,'xmin')
optbPoly.xmin = bounds.xmin;
optbPoly.ymin = bounds.ymin;
end
if isfield(bounds,'xmax')
optbPoly.xmax = bounds.xmax;
optbPoly.ymax = bounds.ymax;
end
if isfield(bounds,'winit')
x_guess = bounds.winit;
end
[A, b, Aeq, beq] = optbPoly.get_constraints();
% 'Algorithm','sqp' for accuracy
% else use default interior point solver
% options = optimoptions('fmincon','Display','iter');
wts = fmincon(@(x)optbPoly.cost(x), x_guess, A, b, Aeq, beq, [], [], ...
@(x)optbPoly.get_nlconstraints);
bPoly.wts = wts;
end