Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6 extension to the ACADO syntax: adding diag #6

Closed
ghorn opened this issue Mar 28, 2013 · 0 comments
Closed

#6 extension to the ACADO syntax: adding diag #6

ghorn opened this issue Mar 28, 2013 · 0 comments
Milestone

Comments

@ghorn
Copy link
Contributor

ghorn commented Mar 28, 2013

Milestone: 1.0 Status: closed Owner: nobody Labels: new feature (4)
Updated: 2012-12-06 Created: 2012-11-22 Creator: Joachim Ferreau Private: No
Why not support the diag command? Here the code for
Vector v = diag(Matrix M) ,
Matrix M = diag(Vector v) ,
ExportVariable Q = diag( name,dim ) ,
the latter setting up a diagonal, user-defined variable (i.e. off-diagonal elements are ignored when exporting code):
I) include/acado/symbolic_expression/acado_syntax.hpp:

include <acado/code_generation/export_variable.hpp>

REFER_NAMESPACE_ACADO Matrix diag ( const REFER_NAMESPACE_ACADO Vector& v );
REFER_NAMESPACE_ACADO Vector diag ( const REFER_NAMESPACE_ACADO Matrix& M );
REFER_NAMESPACE_ACADO ExportVariable diag( const REFER_NAMESPACE_ACADO String& _name, unsigned int _n );
II) src/symbolic_expression/acado_syntax.cpp:
Matrix diag( const Vector& v )
{
int n = v.getDim();

Matrix t = zeros( n,n );
for( int i=0; i<n; ++i )
    t(i,i) = v(i);

return t;

}

Vector diag( const Matrix& M )
{
ASSERT( M.isSquare() == BT_TRUE );

int n = M.getNumRows();

Vector t( n );
for( int i=0; i<n; ++i )
    t(i) = M(i,i);

return t;

}

ExportVariable diag( const String& _name,
unsigned int _n )
{
ExportVariable t( _name, _n,_n );
t = eye( _n );
t.resetDiagonal( );
return t;
}
Discussion

Joachim Ferreau
2012-12-06
status: open --> closed

@ghorn ghorn closed this as completed Mar 28, 2013
zanellia pushed a commit to zanellia/acado that referenced this issue Nov 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant