Initialization of the Parameters. Initialize Parameters on different time points. The matrix M can contain multiple rows for different initializations of the Parameters. Note that these are only initializations, the optimization routine is not forced to use these values exactly. If values should be fixed, use "ocp.subjectTo". Usage: >> algo.initializeParameters(M) Parameters: M m x (n_z + 1) Matrix with initial values where m = number of different initializations on different times n_z = number of Parameters the first column represents the time points the second column represents the first Parameter the thirth column represents the second Parameter ... A warning will be shown when the number of columns is not equal to the number of Parameters + 1 (the time); Example: Example 1: Initialize initial (on t=0) values of 2 Parameters. Initial values are: p1(0) = 5 and p2(0) = 2.5. In this case the matrix M will have one row, the first element is '0' (the time), the second and thirth element are 5 and 2.5 (note that the sequence should be the same as how the Parameters are defined) >> Parameter p1 p2; >> M = [0 5 2.5]; >> algo.initializeParameters(M); Example 2: Initialize on t=0 and t=1 (for example we know what these values will be due to other calculations). Initial values are: p1(0) = 5, p2(0) = 2.5 and p1(1) = 5.5, p2(1) = -1 >> Parameter p1 p2; >> M = [0 5 2.5 1 5.5 -1]; >> algo.initializeParameters(M); Example 3: Although we have two Parameters, we only want to initialize the first: p1(0) = 5. In this case the matrix should only contain one extra column next to the time reference. Note that a warning will be displayed to indicate a possible problem. Ignore this warning. >> Parameter p1 p2; >> M = [0 5]; >> algo.initializeParameters(M); Example 4: We only want to initialize the second Parameter: p2(0) = 2.5. In this case you should reverse the order how the Parameters are defined! >> Parameter p2 p1; >> M = [0 2.5]; >> algo.initializeParameters(M); Licence: This file is part of ACADO Toolkit - (http://www.acadotoolkit.org/) ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization. Copyright (C) 2008-2009 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven. Developed within the Optimization in Engineering Center (OPTEC) under supervision of Moritz Diehl. All rights reserved. ACADO Toolkit is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ACADO Toolkit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with ACADO Toolkit; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Author: David Ariens Date: 2010
0001 function initializeParameters(obj, varargin) 0002 %Initialization of the Parameters. Initialize Parameters on different time points. 0003 % The matrix M can contain multiple rows for different initializations of 0004 % the Parameters. Note that these are only initializations, the optimization 0005 % routine is not forced to use these values exactly. 0006 % If values should be fixed, use "ocp.subjectTo". 0007 % 0008 % Usage: 0009 % >> algo.initializeParameters(M) 0010 % 0011 % Parameters: 0012 % M m x (n_z + 1) Matrix with initial values 0013 % where m = number of different initializations on different times 0014 % n_z = number of Parameters 0015 % the first column represents the time points 0016 % the second column represents the first Parameter 0017 % the thirth column represents the second Parameter 0018 % ... 0019 % 0020 % A warning will be shown when the number of columns is not equal to the 0021 % number of Parameters + 1 (the time); 0022 % 0023 % Example: 0024 % Example 1: Initialize initial (on t=0) values of 2 Parameters. 0025 % Initial values are: p1(0) = 5 and p2(0) = 2.5. In this case the matrix 0026 % M will have one row, the first element is '0' (the time), the second 0027 % and thirth element are 5 and 2.5 (note that the sequence should be the 0028 % same as how the Parameters are defined) 0029 % >> Parameter p1 p2; 0030 % >> M = [0 5 2.5]; 0031 % >> algo.initializeParameters(M); 0032 % 0033 % Example 2: Initialize on t=0 and t=1 (for example we know what these 0034 % values will be due to other calculations). Initial values are: 0035 % p1(0) = 5, p2(0) = 2.5 and p1(1) = 5.5, p2(1) = -1 0036 % >> Parameter p1 p2; 0037 % >> M = [0 5 2.5 0038 % 1 5.5 -1]; 0039 % >> algo.initializeParameters(M); 0040 % 0041 % Example 3: Although we have two Parameters, we only want to 0042 % initialize the first: p1(0) = 5. In this case the matrix should only 0043 % contain one extra column next to the time reference. Note that a 0044 % warning will be displayed to indicate a possible problem. Ignore this 0045 % warning. 0046 % >> Parameter p1 p2; 0047 % >> M = [0 5]; 0048 % >> algo.initializeParameters(M); 0049 % 0050 % Example 4: We only want to initialize the second Parameter: p2(0) = 2.5. 0051 % In this case you should reverse the order how the Parameters are defined! 0052 % >> Parameter p2 p1; 0053 % >> M = [0 2.5]; 0054 % >> algo.initializeParameters(M); 0055 % 0056 % 0057 % Licence: 0058 % This file is part of ACADO Toolkit - (http://www.acadotoolkit.org/) 0059 % 0060 % ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization. 0061 % Copyright (C) 2008-2009 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven. 0062 % Developed within the Optimization in Engineering Center (OPTEC) under 0063 % supervision of Moritz Diehl. All rights reserved. 0064 % 0065 % ACADO Toolkit is free software; you can redistribute it and/or 0066 % modify it under the terms of the GNU Lesser General Public 0067 % License as published by the Free Software Foundation; either 0068 % version 3 of the License, or (at your option) any later version. 0069 % 0070 % ACADO Toolkit is distributed in the hope that it will be useful, 0071 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0072 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0073 % Lesser General Public License for more details. 0074 % 0075 % You should have received a copy of the GNU Lesser General Public 0076 % License along with ACADO Toolkit; if not, write to the Free Software 0077 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0078 % 0079 % Author: David Ariens 0080 % Date: 2010 0081 % 0082 0083 0084 global ACADO_; 0085 0086 if (length(varargin) == 1) 0087 0088 [m n] = size(varargin{1}); 0089 if (length(ACADO_.helper.p) == n) 0090 warning('ACADO:initialize', 'Possible problem in initializeParameters. You have %d parameters and the number of columns in the initialisation matrix is also %d. This is probably not correct since the first column should contain a time reference. This matrix should thus have %d columns. See also <a href="matlab: help acado.OptimizationAlgorithm.initializeParameters">help acado.OptimizationAlgorithm.initializeParameters</a>', length(ACADO_.helper.p), n, length(ACADO_.helper.p)+1); 0091 elseif (length(ACADO_.helper.p) ~= (n-1)) 0092 warning('ACADO:initialize', 'Possible problem in initializeParameters. You have %d parameters and the number of columns in the initialisation matrix is %d. First column should be a time reference, the next columns should be initialisations for all parameters. This matrix should thus have %d columns. See also <a href="matlab: help acado.OptimizationAlgorithm.initializeParameters">help acado.OptimizationAlgorithm.initializeParameters</a>', length(ACADO_.helper.p), n, length(ACADO_.helper.p)+1); 0093 end 0094 0095 obj.initparameters = acado.Matrix(varargin{1}); 0096 0097 else %error 0098 0099 error('ERROR: Invalid initializeParameters call. <a href="matlab: help acado.OptimizationAlgorithm.initializeParameters">help acado.OptimizationAlgorithm.initializeParameters</a>'); 0100 0101 end 0102 0103 0104 end