ldl_solver_eigen.cpp
Go to the documentation of this file.
00001 // Copyright  (C)  2018  Craig Carignan <craigc at ssl dot umd dot edu>
00002 
00003 // Version: 1.0
00004 // Author: Craig Carignan
00005 // Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00006 // URL: http://www.orocos.org/kdl
00007 
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Lesser General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2.1 of the License, or (at your option) any later version.
00012 
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Lesser General Public License for more details.
00017 
00018 // You should have received a copy of the GNU Lesser General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 
00022 #include "ldl_solver_eigen.hpp"
00023 
00024 namespace KDL{
00025 
00026     int ldl_solver_eigen(const Eigen::MatrixXd& A, const Eigen::VectorXd& v, Eigen::MatrixXd& L, Eigen::VectorXd& D, Eigen::VectorXd& vtmp, Eigen::VectorXd& q)
00027     {
00028         const int n = A.rows();
00029         int error=SolverI::E_NOERROR;
00030 
00031         //Check sizes
00032         if(A.cols()!=n || v.rows()!=n || L.rows()!=n || L.cols()!=n || D.rows()!=n || vtmp.rows()!=n || q.rows()!=n)
00033             return (error = SolverI::E_SIZE_MISMATCH);
00034 
00035         for(int i=0;i<n;++i)  {
00036             D(i)=A(i,i);
00037             if(i>0) {
00038                 for(int j=0;j<=i-1;++j)
00039                     D(i) -= D(j)*L(i,j)*L(i,j);
00040             }
00041             for(int j=1;j<n;++j)  {
00042                 if(j>i)  {
00043                     L(j,i)=A(i,j)/D(i);
00044                     if(i>0)  {
00045                         for(int k=0;k<=i-1;++k)
00046                             L(j,i) -= L(j,k)*L(i,k)*D(k)/D(i);
00047                     }
00048                 }
00049             }
00050         }
00051         for(int i=0;i<n;++i)  {
00052             vtmp(i)=v(i);
00053             if(i>0) {
00054                 for(int j=0;j<=i-1;++j)
00055                     vtmp(i) -= L(i,j)*vtmp(j);
00056             }
00057         }
00058         for(int i=n-1;i>=0;--i) {
00059             q(i)=vtmp(i)/D(i);
00060             if(i<n-1)  {
00061                 for(int j=i+1;j<n;++j)
00062                     q(i) -= L(j,i)*q(j);
00063             }
00064         }
00065         // optional: changes diagonal elements of L to 1 as per LDL decomposition
00066         //           A = L * Ddiag * L^T where Ddiag(i,i) = D(i)
00067         for(int i=0;i<n;++i)  {
00068             L(i,i) = 1.;
00069         }
00070         // optional: sets upper triangular, off-diagonal elements of L to 0
00071         //           because algorithm does not do this automatically
00072         if ( n > 1 )
00073         {
00074             for(int i=0;i<n;++i)  {
00075                 for(int j=i+1;j<n;++j)  {
00076                     L(i,j) = 0.0;
00077                 }
00078             }
00079         }
00080         return(error);
00081     }
00082 }


orocos_kdl
Author(s):
autogenerated on Fri Jun 14 2019 19:33:22