Example: Inverse

/*
 * Expression Template Matrix Library
 *
 * Copyright (C) 2004 - 2006 Ricky Lung <mtlung@users.sourceforge.net>
 *
 * This library 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 2.1 of the License, or (at your option) any later version.
 *
 * This library 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 this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

/*
 *  Demonstrate how to find the inverse of a matrix
 *  Currently only Cramer's rule is available
 */

#include <iostream>
#include <iomanip>
#include "../include/exmat.h"

using namespace std;
using namespace exmat;

// Define some matrix types

// A dense matrix of static size 3x3, with float as the element type
typedef Mat<DenseMatCon<float, 3, 3> > Mat3x3f;

int main()
{
    Mat3x3f m1("0 1 3\n\
                2 2 5\n\
                3 1 2\n\
               ");

    cout << "m1 =\n" << m1 << endl;

    // Inverse of a matrix using Cramer's rule

    Mat3x3f inv = adjoint(m1) / determinant(m1);
    cout << "inverse of m1 =\n" << inv << endl;

    cout << "m1 * (m1^-1) =\n" << inv * m1 << endl;

    return 0;
}

Generated on Sat May 6 23:12:04 2006 for Exmat by  doxygen 1.4.6-NO