Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

NEWMATRM.CPP Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

NEWMATRM.CPP

Go to the documentation of this file.
00001 //Owner: Fred
00002 //$$newmatrm.cpp                         rectangular matrix operations
00003 
00004 // Copyright (C) 1991,2,3,4: R B Davies
00005 
00006 #include "newmat.h"
00007 #include "newmatrm.h"
00008 
00009 #ifdef use_namespace
00010 namespace NEWMAT {
00011 #endif
00012 
00013     // operations on rectangular matrices
00014 
00015     void RectMatrixRow::Reset (const Matrix& M, int row, int skip, int length) {
00016         RectMatrixRowCol::Reset
00017             ( M.Store()+row*M.Ncols()+skip, length, 1, M.Ncols() );
00018     }
00019 
00020     void RectMatrixRow::Reset (const Matrix& M, int row) {
00021         RectMatrixRowCol::Reset( M.Store()+row*M.Ncols(), M.Ncols(), 1, M.Ncols() );
00022     }
00023 
00024     void RectMatrixCol::Reset (const Matrix& M, int skip, int col, int length) {
00025         RectMatrixRowCol::Reset
00026             ( M.Store()+col+skip*M.Ncols(), length, M.Ncols(), 1 );
00027     }
00028 
00029     void RectMatrixCol::Reset (const Matrix& M, int col)
00030     { RectMatrixRowCol::Reset( M.Store()+col, M.Nrows(), M.Ncols(), 1 ); }
00031 
00032     Real RectMatrixRowCol::SumSquare() const {
00033         long_Real sum = 0.0; int i = n; Real* s = store; int d = spacing;
00034         while (i--) { sum += (long_Real)*s * *s; s += d; }
00035         return (Real)sum;
00036     }
00037 
00038     Real RectMatrixRowCol::operator*(const RectMatrixRowCol& rmrc) const {
00039         long_Real sum = 0.0; int i = n;
00040         Real* s = store; int d = spacing;
00041         Real* s1 = rmrc.store; int d1 = rmrc.spacing;
00042         if (i!=rmrc.n) {
00043             Tracer tr("newmatrm");
00044             Throw(InternalException("Dimensions differ in *"));
00045         }
00046         while (i--) { sum += (long_Real)*s * *s1; s += d; s1 += d1; }
00047         return (Real)sum;
00048     }
00049 
00050     void RectMatrixRowCol::AddScaled(const RectMatrixRowCol& rmrc, Real r) {
00051         int i = n; Real* s = store; int d = spacing;
00052         Real* s1 = rmrc.store; int d1 = rmrc.spacing;
00053         if (i!=rmrc.n) {
00054             Tracer tr("newmatrm");
00055             Throw(InternalException("Dimensions differ in AddScaled"));
00056         }
00057         while (i--) { *s += *s1 * r; s += d; s1 += d1; }
00058     }
00059 
00060     void RectMatrixRowCol::Divide(const RectMatrixRowCol& rmrc, Real r) {
00061         int i = n; Real* s = store; int d = spacing;
00062         Real* s1 = rmrc.store; int d1 = rmrc.spacing;
00063         if (i!=rmrc.n) {
00064             Tracer tr("newmatrm");
00065             Throw(InternalException("Dimensions differ in Divide"));
00066         }
00067         while (i--) { *s = *s1 / r; s += d; s1 += d1; }
00068     }
00069 
00070     void RectMatrixRowCol::Divide(Real r) {
00071         int i = n; Real* s = store; int d = spacing;
00072         while (i--) { *s /= r; s += d; }
00073     }
00074 
00075     void RectMatrixRowCol::Negate() {
00076         int i = n; Real* s = store; int d = spacing;
00077         while (i--) { *s = - *s; s += d; }
00078     }
00079 
00080     void RectMatrixRowCol::Zero() {
00081         int i = n; Real* s = store; int d = spacing;
00082         while (i--) { *s = 0.0; s += d; }
00083     }
00084 
00085     void ComplexScale(RectMatrixCol& U, RectMatrixCol& V, Real x, Real y) {
00086         int n = U.n;
00087         if (n != V.n) {
00088             Tracer tr("newmatrm");
00089             Throw(InternalException("Dimensions differ in ComplexScale"));
00090         }
00091         Real* u = U.store; Real* v = V.store;
00092         int su = U.spacing; int sv = V.spacing;
00093         while (n--) {
00094             Real z = *u * x - *v * y;  *v =  *u * y + *v * x;  *u = z;
00095             u += su;  v += sv;
00096         }
00097     }
00098 
00099     void Rotate(RectMatrixCol& U, RectMatrixCol& V, Real tau, Real s) {
00100         //  (U, V) = (U, V) * (c, s)  where  tau = s/(1+c), c^2 + s^2 = 1
00101         int n = U.n;
00102         if (n != V.n) {
00103             Tracer tr("newmatrm");
00104             Throw(InternalException("Dimensions differ in Rotate"));
00105         }
00106         Real* u = U.store; Real* v = V.store;
00107         int su = U.spacing; int sv = V.spacing;
00108         while (n--) {
00109             Real zu = *u; Real zv = *v;
00110             *u -= s * (zv + zu * tau); *v += s * (zu - zv * tau);
00111             u += su;  v += sv;
00112         }
00113     }
00114 
00115 #ifdef use_namespace
00116 }
00117 #endif

Generated on Fri Aug 23 01:37:11 2002 for VirtualU by doxygen1.2.17