example.c
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #include "binary_library.h"
00026 #include "stdio.h"
00027 
00028 void demo_MatrixXd()
00029 {
00030   struct C_MatrixXd *matrix1, *matrix2, *result;
00031   printf("*** demo_MatrixXd ***\n");
00032   
00033   matrix1 = MatrixXd_new(3, 3);
00034   MatrixXd_set_zero(matrix1);
00035   MatrixXd_set_coeff(matrix1, 0, 1, 2.5);
00036   MatrixXd_set_coeff(matrix1, 1, 0, 1.4);
00037   printf("Here is matrix1:\n");
00038   MatrixXd_print(matrix1);
00039 
00040   matrix2 = MatrixXd_new(3, 3);
00041   MatrixXd_multiply(matrix1, matrix1, matrix2);
00042   printf("Here is matrix1*matrix1:\n");
00043   MatrixXd_print(matrix2);
00044 
00045   MatrixXd_delete(matrix1);
00046   MatrixXd_delete(matrix2);
00047 }
00048 
00049 // this helper function takes a plain C array and prints it in one line
00050 void print_array(double *array, int n)
00051 {
00052   struct C_Map_MatrixXd *m = Map_MatrixXd_new(array, 1, n);
00053   Map_MatrixXd_print(m);
00054   Map_MatrixXd_delete(m);
00055 }
00056 
00057 void demo_Map_MatrixXd()
00058 {
00059   struct C_Map_MatrixXd *map;
00060   double array[5];
00061   int i;
00062   printf("*** demo_Map_MatrixXd ***\n");
00063   
00064   for(i = 0; i < 5; ++i) array[i] = i;
00065   printf("Initially, the array is:\n");
00066   print_array(array, 5);
00067   
00068   map = Map_MatrixXd_new(array, 5, 1);
00069   Map_MatrixXd_add(map, map, map);
00070   Map_MatrixXd_delete(map);
00071 
00072   printf("Now the array is:\n");
00073   print_array(array, 5);
00074 }
00075 
00076 int main()
00077 {
00078   demo_MatrixXd();
00079   demo_Map_MatrixXd();
00080 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:08