Home > matlab > acado > packages > +acado > @DifferentialEquation > linkMatlabODE.m

linkMatlabODE

PURPOSE ^

Link a matlab ODE black box model to ACADO

SYNOPSIS ^

function linkMatlabODE(obj, varargin)

DESCRIPTION ^

Link a matlab ODE black box model to ACADO

  Usage:
    >> DifferentialEquation.linkMatlabODE(fcnHandleODE)
    >> DifferentialEquation.linkMatlabODE(fcnHandleODE, fcnHandleJacobian)

  Parameters:
    fcnHandleODE       Reference to function handle            [STRING]
    fcnHandleJacobian  Reference to Jacobian function handle   [STRING]

  Example:
    >> f = acado.DifferentialEquation();
    >> f.linkMatlabODE('myODE');
    or
    >> f.linkMatlabODE('myODE', 'myJacobian');

    The file fcnHandleODE should have this header: 
       [ dx ] = fcnHandleODE(t,x,u,p,w )

    Analogous, the file fcnHandleJacobian will have this header:
       [ J ] = fcnHandleJacobian( t,x,u,p,w )

    Here t is a numeric containing the current time, x is a vector
    containing all states, u a vector with all controls (if any), p a
    vector with all parameters (if any) and w a vector with all
    disturbances (if any).

    dx will be a vector of length "length(x)" containing dot(x). J will be
    a matrix of size "length(x)" times "length(x)+length(u)+length(p)+length(w)"


  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: 2009-2010

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function linkMatlabODE(obj, varargin)
0002 %Link a matlab ODE black box model to ACADO
0003 %
0004 %  Usage:
0005 %    >> DifferentialEquation.linkMatlabODE(fcnHandleODE)
0006 %    >> DifferentialEquation.linkMatlabODE(fcnHandleODE, fcnHandleJacobian)
0007 %
0008 %  Parameters:
0009 %    fcnHandleODE       Reference to function handle            [STRING]
0010 %    fcnHandleJacobian  Reference to Jacobian function handle   [STRING]
0011 %
0012 %  Example:
0013 %    >> f = acado.DifferentialEquation();
0014 %    >> f.linkMatlabODE('myODE');
0015 %    or
0016 %    >> f.linkMatlabODE('myODE', 'myJacobian');
0017 %
0018 %    The file fcnHandleODE should have this header:
0019 %       [ dx ] = fcnHandleODE(t,x,u,p,w )
0020 %
0021 %    Analogous, the file fcnHandleJacobian will have this header:
0022 %       [ J ] = fcnHandleJacobian( t,x,u,p,w )
0023 %
0024 %    Here t is a numeric containing the current time, x is a vector
0025 %    containing all states, u a vector with all controls (if any), p a
0026 %    vector with all parameters (if any) and w a vector with all
0027 %    disturbances (if any).
0028 %
0029 %    dx will be a vector of length "length(x)" containing dot(x). J will be
0030 %    a matrix of size "length(x)" times "length(x)+length(u)+length(p)+length(w)"
0031 %
0032 %
0033 %  Licence:
0034 %    This file is part of ACADO Toolkit  - (http://www.acadotoolkit.org/)
0035 %
0036 %    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
0037 %    Copyright (C) 2008-2009 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven.
0038 %    Developed within the Optimization in Engineering Center (OPTEC) under
0039 %    supervision of Moritz Diehl. All rights reserved.
0040 %
0041 %    ACADO Toolkit is free software; you can redistribute it and/or
0042 %    modify it under the terms of the GNU Lesser General Public
0043 %    License as published by the Free Software Foundation; either
0044 %    version 3 of the License, or (at your option) any later version.
0045 %
0046 %    ACADO Toolkit is distributed in the hope that it will be useful,
0047 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
0048 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0049 %    Lesser General Public License for more details.
0050 %
0051 %    You should have received a copy of the GNU Lesser General Public
0052 %    License along with ACADO Toolkit; if not, write to the Free Software
0053 %    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0054 %
0055 %    Author: David Ariens
0056 %    Date: 2009-2010
0057 %
0058     
0059 if (nargin ~= 2 && nargin ~= 3)
0060      error('ERROR in linkMatlabODE. See <a href="matlab: help acado.DifferentialEquation.linkMatlabODE">help acado.DifferentialEquation.linkMatlabODE</a>');         
0061 end
0062 
0063 if (~isempty(obj.differentialList) || ~isempty(obj.matlabODE_fcnHandle) || ~isempty(obj.matlabDAE_fcnHandle) || ~isempty(obj.cfunction_file))
0064    error('Only _one_ Matlab DAE or ODE or C++ file can be linked. Or use ACADO symbolic notation.');
0065 end
0066 
0067 if (nargin == 2 || nargin == 3)   % ODE
0068     
0069     fcnHandle = varargin{1};
0070     
0071     if(isempty(fcnHandle) || isvarname(fcnHandle) ~= 1)
0072         error('ERROR in linkMatlabODE. fcnHandle should be a string refering to the name of a function. See <a href="matlab: help acado.DifferentialEquation.linkMatlabODE">help acado.DifferentialEquation.linkMatlabODE</a>');         
0073     end
0074     
0075     %test = feval( fcnHandle,t,x,u,p,w ); % This line should run without warnings.
0076     
0077     obj.matlabODE_fcnHandle = fcnHandle;
0078     
0079 end   
0080 
0081     
0082 if (nargin == 3)                  % JACOBIAN
0083     
0084     fcnHandle = varargin{2};
0085     
0086     if(isempty(fcnHandle) || isvarname(fcnHandle) ~= 1)
0087         error('ERROR in linkMatlabJacobian. fcnHandle should be a string refering to the name of a function. See <a href="matlab: help acado.DifferentialEquation.linkMatlabODE">help acado.DifferentialEquation.linkMatlabODE</a>');         
0088     end
0089     
0090     obj.matlabJacobian_fcnHandle = fcnHandle;
0091 
0092 end    
0093     
0094 
0095 end

www.acadotoolkit.org/matlab
Generated on Tue 01-Jun-2010 20:14:12 by m2html © 2005