////////////////////////////////////////////////////////////////////////////// // // Title : exercise1.cpp // Project : OSCAR tutorial // Created : May 30, 1998 // Author : Mitch Pryor // Platforms : PC // Copyright : Copyright© The University of Texas at Austin, 2002. // All rights reserved. // // This software and documentation constitute an unpublished work // and contain valuable trade secrets and proprietary information // belonging to University. None of the foregoing material may be // copied or duplicated or disclosed without the express, written // permission of University. UNIVERSITY EXPRESSLY DISCLAIMS ANY // AND ALL WARRANTIES CONCERNING THIS SOFTWARE AND DOCUMENTATION, // INCLUDING ANY WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE, AND WARRANTIES OF PERFORMANCE, AND ANY WARRANTY // THAT MIGHT OTHERWISE ARISE FROM COURSE OF DEALING OR USAGE OF TRADE. // NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH RESPECT TO THE USE OF // THE SOFTWARE OR DOCUMENTATION. Under no circumstances shall // University be liable for incidental, special, indirect, direct or // consequential damages or loss of profits, interruption of business, // or related expenses which may arise from use of software or documentation, // including but not limited to those resulting from defects in software // and/or documentation, or loss or inaccuracy of data of any kind. // // Purpose : Solution to Exercise 1 of the OSCAR Guide // ////////////////////////////////////////////////////////////////////////////// #include #include "Math\Vector.h" #include "Math\Matrix.h" #include "Math\Tensor.h" #include "FileData\MatrixData.h" int main(void) { //Part 1: Matrix Manipulation RRMatrix mA(2, 2); // matrix A RRMatrix mB(2, 2); // matrix B RRMatrix mProduct(2, 2); // the ( ) overide contains error checking in debug and release mode mA(0, 0) = 1; mA(0, 1) = 2; mA(1, 0) = 3; mA(1, 1) = 4; // the method '.at()' only contains error checking in debug mode. mB.at(0, 0) = 1; mB.at(0, 1) = 1; mB.at(1, 0) = 1; mB.at(1, 1) = 0; Multiply(mA, mB, mProduct); cout << "mA*mB:\n" << mA*mB << "\n" << endl; cout << "Multiply(mA, mB, mProduct)\n" << mProduct << "\n"; cout << "Transpose:\n" << mProduct.t() << "\n"; cout << "Inverse:\n" << ~mProduct << "\n"; //Part 2: Create a Matrix from file data RRMatrixData matrixFile("DataFiles/MatrixFile.txt", 3); RRMatrix mC = matrixFile.GetParameters(); cout << "mC: \n" << mC << endl; //Part 3: Create and Populate a tensor RRTensor tA(3, 3, 3); for(int i=0; i<3; i++){ for(int j=0; j<3; j++){ for(int k=0; k<3; k++){ tA.at(i, j, k) = (i+1)*(j+1)*(k+1); }}} cout << "Tensor:\n" << tA << "\n"; //Part 4: Moving information between tensors, matrices, and vectors RRVector vA(3); RRMatrix mD(3,3); mD = tA.at(1); vA = GetRow(1, mD); cout << "Vector vA: " << vA << endl; return 0; }