00001
00002
00004
00005 #include "MatrixOperations.h"
00006
00008
00010
00011 CMatrixOperations::CMatrixOperations()
00012 {
00013
00014 }
00015
00016 CMatrixOperations::~CMatrixOperations()
00017 {
00018
00019 }
00020
00021 double CMatrixOperations::DotProduct(double *v1, double *v2, int size)
00022 {
00023 double sum = 0.0;
00024 for(int i = 0; i < size; i++)
00025 {
00026 sum += v1[i]*v2[i];
00027 }
00028 return sum;
00029 }
00030
00031 double CMatrixOperations::VectorL2Norm(double *v, int size)
00032 {
00033 double norm = 0.0;
00034 for(int i = 0; i < size; i++)
00035 {
00036 norm += v[i]*v[i];
00037 }
00038 return sqrt(norm);
00039 }
00040
00041 double CMatrixOperations::VectorSupNorm(double *v, int size)
00042 {
00043 double norm = 0.0;
00044 for(int i = 0; i < size; i++)
00045 {
00046 norm = __max(norm,fabs(v[i]));
00047 }
00048 return norm;
00049 }
00050
00051 void CMatrixOperations::ElementCopy(double *vsource, double *vtarget, int size)
00052 {
00053 for(int i = 0; i < size; i++)
00054 {
00055 vtarget[i] = vsource[i];
00056 }
00057 return;
00058 }
00059
00060 void CMatrixOperations::RescaleVector(double *v, double scale, int size)
00061 {
00062 for(int i = 0; i < size; i++)
00063 {
00064 v[i] = scale*v[i];
00065 }
00066 return;
00067 }
00068
00069 void CMatrixOperations::TwoVectorLC(double a, double *x, double b, double *y, double *z, int size)
00070 {
00071 for(int i = 0; i < size; i++)
00072 {
00073 z[i] = a*x[i] + b*y[i];
00074 }
00075 return;
00076 }