/* * ====================================================================== * Test Program and Functions for Basic Matrix Operations. * ====================================================================== * Copyright (C) 1994-96 by Mark Austin and David Mazzoni. * * This software is provided "as is" without express or implied warranty. * Permission is granted to use this software on any computer system, * and to redistribute it freely, subject to the following restrictions: * * 1. The authors are not responsible for the consequences of use of * this software, even if they arise from defects in the software. * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 4. This notice is to remain intact. * * Written By : M. Austin June 1994 * ====================================================================== */ #include #include "matrix.h" #include "miscellaneous.h" /* #define GENERATE_ERRORS */ int main( void ) { MATRIX *spA, *spB, *spC, *spD, *spE; int ii, ij; /* [a] : Allocate, instantiate, and print two small matrices */ spA = matAllocIndirect( "[A]" , DoubleArray, 2, 2 ); spB = matAllocIndirect( "[B]" , DoubleArray, 2, 2 ); spC = matAllocIndirect( "[C]" , DoubleArray, 3, 2 ); for ( ii = 1 ; ii <= 2; ii = ii + 1 ) for ( ij = 1 ; ij <= 2; ij = ij + 1 ) { spA->uMatrix.dpp[ ii - 1 ][ ij - 1 ] = ii - ij; spB->uMatrix.dpp[ ii - 1 ][ ij - 1 ] = ii + ij; spC->uMatrix.dpp[ ii - 1 ][ ij - 1 ] = 2*ii; } matPrintIndirectDouble( spA ); matPrintIndirectDouble( spB ); matPrintIndirectDouble( spC ); /* [b] : Add Two Matrices */ spD = matAddIndirectDouble( spA, spB ); spD->cpName = saveString( "[D] = [A] + [B]", __FILE__, __LINE__ ); matPrintIndirectDouble( spD ); /* [c] : Multiply Two Matrices */ spE = matMultIndirectDouble( spA, spB ); spE->cpName = saveString( "[E] = [A]*[B]", __FILE__, __LINE__ ); matPrintIndirectDouble( spE ); /* [d] : Generate Error Conditions : Try to compute [A] + [C] ?? */ #ifdef GENERATE_ERRORS printf( "\n*** Generate Error Conditions : Try to compute [A] + [C] \n\n" ); spE = matAddIndirectDouble( spA, spC ); spE->cpName = saveString( "[E] = [A] + [C]", __FILE__, __LINE__ ); matPrintIndirectDouble( spE ); printf( "\n*** End Error Tests \n" ); #endif /* [e] : Clean up before terminating program */ matFreeIndirect( spA ); matFreeIndirect( spB ); matFreeIndirect( spD ); matFreeIndirect( spE ); }