00001 #ifndef __RealVector_H__ 00002 #define __RealVector_H__ 00003 00004 00005 00024 #include <stdio.h> 00025 00026 class RealVectorT; 00027 00028 class RealVector 00029 { 00030 private: 00031 00032 int dataSize; 00033 double* data; // base 0 00034 00035 double* data1; 00036 00037 public: 00038 00039 RealVector(){dataSize=0; data=0;} 00040 RealVector(int size); 00041 RealVector(int size, double adata); 00042 RealVector(int size, double* adata); 00043 RealVector(const RealVector& v); 00044 RealVector operator=(const RealVector& v); 00045 00046 ~RealVector(){ data=0; delete[] data1; } 00047 00048 RealVectorT t(); 00049 00050 RealVector* copy(){ return new RealVector(*this); } 00051 00052 RealVector* sub(int start, int step, int end); 00053 00054 inline int size()const { return dataSize; } 00055 00056 void load(RealVector* v); 00057 double* getData(){return data;} 00058 00059 // base 0 00060 inline void set0(int index, double value){ data[index]= value; } 00061 inline double get0(int index)const { return data[index]; } 00062 00063 // base 1 00064 inline void set(int index, double value){ data1[index]= value; } 00065 inline double get(int index)const { return data1[index]; } 00066 00067 void setAll(double value); 00068 00069 // computations 00070 double vT_v(); 00071 double vT_v(RealVector* v2); 00072 double norme2(); 00073 double sum(); 00074 00075 double minimum(); 00076 double maximum(); 00077 double mean(){ return sum()/dataSize; } 00078 double sigma(); 00079 00080 // math vectorial op 00081 RealVector sqrt(); 00082 RealVector pow(double pow); 00083 RealVector sqr(); 00084 RealVector exp(); 00085 RealVector log(); 00086 RealVector log(double base); 00087 00088 RealVector sin(); 00089 RealVector cos(); 00090 RealVector tan(); 00091 00092 // differences 00093 double undividedDiff(int cellj, int order); 00094 double dividedDiff(int cellj, int order, double dx=1.0); // uniform 00095 double dividedDiff(int cellj, int order, RealVector* x); // non-uniform 00096 00097 // scalar single operations 00098 void operator+=(double value); 00099 void operator-=(double value); 00100 void operator*=(double value); 00101 void operator/=(double value); 00102 00103 // vector single operations 00104 void operator+=(const RealVector& v); 00105 void operator-=(const RealVector& v); 00106 void operator*=(const RealVector& v); 00107 void operator/=(const RealVector& v); 00108 00109 // friends 00110 friend double operator*(const RealVectorT& vt,const RealVector& u); // scalar product 00111 00112 friend RealVector operator+(const RealVector& v, double a); // v<op>a 00113 friend RealVector operator+(double a, const RealVector& v); // a<op>v 00114 friend RealVector operator-(const RealVector& v, double a); // v<op>a 00115 friend RealVector operator-(double a, const RealVector& v); // a<op>v 00116 friend RealVector operator*( const RealVector& v, double a); // v<op>a 00117 friend RealVector operator*(double a,const RealVector& v); // a<op>v 00118 friend RealVector operator/(const RealVector& v, double a); // v<op>a 00119 00120 friend RealVector operator+(const RealVector& v1, const RealVector& v2); // v1<op>v2 00121 friend RealVector operator-(const RealVector& v1, const RealVector& v2); // v1<op>v2 00122 00123 void output(); 00124 void output(FILE* file); 00125 }; 00126 00127 #endif 00128 00129