#ifndef __JMATRIX1D__ #define __JMATRIX1D__ #include #include #include #include #include "JIO/JSerialisable.hh" #include "JLang/JEquals.hh" #include "JLang/JManip.hh" #include "JMath/JMath.hh" /** * \author mdejong */ namespace JMATH {} namespace JPP { using namespace JMATH; } namespace JMATH { using JIO::JReader; using JIO::JWriter; using JLANG::JEquals; /** * 1 x 1 matrix */ class JMatrix1D : public JMath , public JEquals { public: using JMath::mul; /** * Default constructor. */ JMatrix1D() : a00(0.0) {} /** * Contructor. * * \param __a00 (0,0) */ JMatrix1D(const double __a00) : a00(__a00) {} /** * Get reference to unique instance of this class object. * * \return zero matrix */ static const JMatrix1D& getInstance() { static JMatrix1D matrix; return matrix; } /** * Set to identity matrix. * * \return this matrix */ JMatrix1D& setIdentity() { a00 = 1.0; return *this; } /** * Get reference to unique instance of this class object. * * \return identity matrix */ static const JMatrix1D& getIdentity() { static JMatrix1D matrix(JMatrix1D().setIdentity()); return matrix; } /** * Set matrix. * * \param A matrix */ void set(const JMatrix1D& A) { static_cast(*this) = A; } /** * Set matrix to the null matrix. * * \return this matrix */ JMatrix1D& reset() { *this = JMatrix1D(); return *this; } /** * Transpose. * * \return this matrix */ JMatrix1D& transpose() { return *this; } /** * Negate matrix. * * \return -this matrix */ JMatrix1D& negate() { a00 = -a00; return *this; } /** * Matrix addition. * * \param A matrix * \return this matrix + A */ JMatrix1D& add(const JMatrix1D& A) { a00 += A.a00; return *this; } /** * Matrix subtraction. * * \param A matrix * \return this matrix - A */ JMatrix1D& sub(const JMatrix1D& A) { a00 -= A.a00; return *this; } /** * Scale matrix. * * \param factor factor * \return this matrix * factor */ JMatrix1D& mul(const double factor) { a00 *= factor; return *this; } /** * Scale matrix. * * \param factor factor * \return this matrix / factor */ JMatrix1D& div(const double factor) { a00 /= factor; return *this; } /** * Matrix multiplication. * * \param A matrix * \param B matrix * \return this matrix */ JMatrix1D& mul(const JMatrix1D& A, const JMatrix1D& B) { a00 = A.a00 * B.a00; return *this; } /** * Equality. * * \param A matrix * \param eps numerical precision * \return true if matrices identical; else false */ bool equals(const JMatrix1D& A, const double eps = std::numeric_limits::min()) const { return (fabs(a00 - A.a00) <= eps); } /** * Test identity. * * \param eps numerical precision * \return true if identity matrix; else false */ bool isIdentity(const double eps = std::numeric_limits::min()) const { return equals(getIdentity(), eps); } /** * Get determinant of matrix. * * \return determinant of matrix */ double getDeterminant() const { return a00; } /** * Transform. * * \param __x x value */ void transform(double& __x) const { __x = a00 * __x; } /** * Read matrix from input. * * \param in reader * \param matrix matrix * \return reader */ friend inline JReader& operator>>(JReader& in, JMatrix1D& matrix) { in >> matrix.a00; return in; } /** * Write matrix to output. * * \param out writer * \param matrix matrix * \return writer */ friend inline JWriter& operator<<(JWriter& out, const JMatrix1D& matrix) { out << matrix.a00; return out; } /** * Print ASCII formatted output. * * \param out output stream * \param A matrix * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JMatrix1D& A) { using namespace std; const JFormat format(out, getFormat(JFormat_t(10, 3, std::ios::fixed | std::ios::showpos))); out << format << A.a00 << endl; return out; } double a00; }; } #endif