-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgradCost_myProblem.m
77 lines (65 loc) · 2.44 KB
/
gradCost_myProblem.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
function [dL,dE]=gradCost_myProblem(L,X,Xr,U,Ur,P,t,E,x0,xf,u0,uf,p,t0,tf,data)
%GRADCOST - Return the gradient of the cost in analytic form
%
% Syntax: [dL,dE]=gradCost(L,X,Xr,U,Ur,P,t,E,x0,xf,u0,uf,p,tf,data)
%
% Inputs:
% see directCollocation.m
%
% Outputs:
% dL - Gradient of the stage cost L wrt. t,p,x,u
% dE - Gradient of E with respect to tf,p,x0,u0,uf,xf
%
% Gradient dL:
% If the analytic form for L is supplied, set dL.flag=1 otherwise set
% dL.flag=0. If tf is a variable of the problem and dL.flag=1 it is necessary to
% specify the derivative of L with respect to time t.
% You need to specify dL.dx and dL.du whenever dL.flag=1.
% dL.dx, dL.du, dL.dp and dL.dt must be vectorized.
% The derivative of L with respect to the i-th state variable, evaluated along all the horizon,
% corresponds to the i-th column of dL.dx. The same rule holds for dL.du, dL.dp, dL.dt
% The i-th state and input
% xi and ui, evaluated at the time instants t=[t0,...tk,...tf], are column vectors
% taken as X(:,i) and U(:,i)
% The i-th state and input references xri and uri for the i-th variable are column vectors taken
% as Xr(:,i) and Ur(:,i)
%
% Gradient dE:
% If the analytic form for E is supplied set dE.flag=1 otherwise set
% dE.flag=0. If the derivative of E does not depend on some variable it is possible to set
% the respective variable as the empty matrix. For instance if it does not depend on x0 set
% dE.dx0=[];
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% Copyright (C) 2019 Yuanbo Nie, Omar Faqir, and Eric Kerrigan. All Rights Reserved.
% The contribution of Paola Falugi, Eric Kerrigan and Eugene van Wyk for the work on ICLOCS Version 1 (2010) is kindly acknowledged.
% This code is published under the MIT License.
% Department of Aeronautics and Department of Electrical and Electronic Engineering,
% Imperial College London London England, UK
% ICLOCS (Imperial College London Optimal Control) Version 2.5
% 1 Aug 2019
%------------- BEGIN CODE --------------
[ X,Xr,U,Ur,P,x0,xf,u0,uf,p,data ] = batchScaleBack(X,Xr,U,Ur,P,x0,xf,u0,uf,p,data);
% Stage cost gradients
n=deal(data.sizes{3});
Lt=ones(size(t));
dL.flag=0;
dL.dp=[];
dL.dt=[];
dL.dx=[];
dL.du=[];
% Terminal cost gradients
dE.flag=0;
dE.dt0=[];
dE.dtf=[];
dE.dp=[];
dE.dx0=[];
dE.du0=[];
dE.dxf=[];
dE.duf=[];
[ dL,dE ] = batchScaleGradCost(dL,dE,data);
%------------- END CODE --------------