BWAPI
|
00001 /****************************************************************** 00002 * Core Library Version 1.7, August 2004 00003 * Copyright (c) 1995-2002 Exact Computation Project 00004 * 00005 * File: LinearAlgebra.h 00006 * Synopsis: 00007 * Linear Algebra Extension of Core Library introducing 00008 * class Vector 00009 * class Matrix 00010 * 00011 * Written by 00012 * Shubin Zhao (shubinz@cs.nyu.edu) (2001) 00013 * 00014 * WWW URL: http://cs.nyu.edu/exact/ 00015 * Email: exact@cs.nyu.edu 00016 * 00017 * $Id: linearAlgebra.h 37060 2007-03-13 18:10:39Z reichel $ 00018 *****************************************************************/ 00019 00020 #ifndef CORE_LINEAR_ALGEBRA_H 00021 #define CORE_LINEAR_ALGEBRA_H 00022 00023 #ifndef CORE_LEVEL 00024 # define CORE_LEVEL 3 00025 #endif 00026 00027 #include <cstdarg> 00028 #include <CGAL/CORE/CORE.h> 00029 00030 class Vector; 00031 class Matrix; 00032 00034 // Class Vector 00035 // Generic vectors 00036 // Operations implemented: addition, subtraction, dot product 00038 00039 class Vector { 00040 private: 00041 int dim; 00042 double* _rep; 00043 public: 00044 class RangeException { }; 00045 class ArithmeticException { }; 00046 00047 explicit Vector(int); 00048 Vector(); 00049 Vector(double, double); 00050 Vector(double, double, double); 00051 Vector(const Vector&); 00052 Vector(int, double *); 00053 ~Vector(); 00054 00055 const Vector& operator=(const Vector&); 00056 00057 bool operator==(const Vector&); 00058 bool operator!=(const Vector&); 00059 const Vector& operator+=(const Vector&); 00060 const Vector& operator-=(const Vector&); 00061 const Vector& operator*=(double); 00062 00063 const double& operator[](int) const; 00064 double& operator[](int); 00065 00066 double norm() const; 00067 double maxnorm() const; 00068 double infnorm() const; 00069 double dimension() const {return dim;} 00070 bool isZero() const; 00071 Vector cross(const Vector &v) const; 00072 static Vector crossProduct(int, ...); 00073 00074 friend Vector operator+(const Vector&, const Vector&); 00075 friend Vector operator-(const Vector&, const Vector&); 00076 friend Vector operator-(const Vector&); 00077 friend Vector operator*(const Vector&, double); 00078 friend Vector operator*(double, const Vector&); 00079 friend Vector operator*(const Matrix&, const Vector&); 00080 friend Vector operator*(const Vector&, const Matrix&); 00081 friend double dotProduct(const Vector&, const Vector&); 00082 00083 friend std::istream& operator>>(std::istream&, Vector&); 00084 friend std::ostream& operator<<(std::ostream&, const Vector&); 00085 }; 00086 00088 // Class Matrix 00089 // Generic matrices 00090 // Operations implemented: addition, subtraction, multiplication 00092 00093 class Matrix { 00094 private: 00095 int dim1, dim2; 00096 double* _rep; 00097 00098 public: 00099 class RangeException { }; 00100 class ArithmeticException { }; 00101 00102 explicit Matrix(int); 00103 Matrix(int, int); 00104 Matrix(int, int, double *); 00105 Matrix(double, double, 00106 double, double); 00107 Matrix(double, double, double, 00108 double, double, double, 00109 double, double, double); 00110 Matrix(const Matrix&); 00111 ~Matrix(); 00112 00113 Matrix& operator=(const Matrix&); 00114 00115 bool operator==(const Matrix&); 00116 bool operator!=(const Matrix&); 00117 00118 const Matrix& operator+=(const Matrix&); 00119 const Matrix& operator-=(const Matrix&); 00120 const Matrix& operator*=(double); 00121 00122 const double& operator()(int, int) const; 00123 double& operator()(int, int); 00124 00125 // added by chen li 00126 // const Vector& row(int i) const; 00127 // const Vector& col(int i) const; 00128 Matrix matrixAlgebraRemainder(int, int) const; 00129 double valueAlgebraRemainder(int, int) const; 00130 const Matrix& transpose(); 00131 00132 double determinant() const; 00133 00134 int dimension_1() const { return dim1; } 00135 int dimension_2() const { return dim2; } 00136 00137 friend Matrix operator+(const Matrix&, const Matrix&); 00138 friend Matrix operator-(const Matrix&, const Matrix&); 00139 friend Matrix operator*(const Matrix&, double); 00140 friend Matrix operator*(double, const Matrix&); 00141 friend Vector operator*(const Vector&, const Matrix&); 00142 friend Vector operator*(const Matrix&, const Vector&); 00143 friend Matrix operator*(const Matrix&, const Matrix&); 00144 friend Matrix transpose(const Matrix&); 00145 00146 friend double det(const double a, const double b, 00147 const double c, const double d); 00148 friend double det(const Vector u, const Vector & v); // u,v are 2d vectors 00149 00150 friend std::istream& operator>>(std::istream&, Matrix&); 00151 friend std::ostream& operator<<(std::ostream&, const Matrix&); 00152 00153 }; //Matrix 00154 00155 #endif 00156