00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "doublematrix.h"
00024 #include <cmath>
00025 #include <iostream>
00026 #ifndef BG_H
00027 #define BG_H
00028
00029 namespace matvec {
00030
00031
00032 class BG{
00033 public:
00034 static unsigned dimen;
00035 static doubleMatrix x;
00036 double f;
00037 doubleMatrix d;
00038 doubleMatrix D;
00039
00040 BG();
00041 BG(unsigned x_i, double b);
00042 BG(double a);
00043 BG(const BG &a);
00044
00045 static void set_dimen(unsigned i){
00046 dimen = i;
00047 x.resize(dimen,1,0.0);
00048 }
00049 BG& initialize(unsigned i, double b);
00050
00051 friend BG operator+(const BG &a, const BG &b);
00052 friend BG operator-(const BG &a, const BG &b);
00053 friend BG operator*(const BG &a, const BG &b);
00054 friend BG operator/(const BG &a, const BG &b);
00055 friend BG operator-(const BG &a);
00056 friend BG operator/(double a, const BG &b);
00057 friend BG operator+(double a, const BG &b);
00058 friend BG operator-(double a, const BG &b);
00059 friend BG operator*(double a, const BG &b);
00060
00061 friend BG operator+ (const BG &a, double b);
00062 friend BG operator- (const BG &a, double b);
00063 friend BG operator* (const BG &a, double b);
00064 friend BG operator/ (const BG &a, double b);
00065
00066 friend bool operator<=(const BG &a, double b){return a.f<=b;};
00067 friend bool operator< (const BG &a, double b){return a.f< b;};
00068 friend bool operator>=(const BG &a, double b){return a.f>=b;};
00069 friend bool operator> (const BG &a, double b){return a.f> b;};
00070 friend bool operator==(const BG &a, double b){return a.f==b;};
00071 friend bool operator!=(const BG &a, double b){return a.f!=b;};
00072
00073 friend bool operator<=(const BG &a, const BG &b){return a.f<=b.f;};
00074 friend bool operator< (const BG &a, const BG &b){return a.f< b.f;};
00075 friend bool operator>=(const BG &a, const BG &b){return a.f>=b.f;};
00076 friend bool operator> (const BG &a, const BG &b){return a.f> b.f;};
00077 friend bool operator==(const BG &a, const BG &b){return a.f==b.f;};
00078 friend bool operator!=(const BG &a, const BG &b){return a.f!=b.f;};
00079
00080 friend bool operator<=(double b, const BG &a){return b<=a.f;};
00081 friend bool operator< (double b, const BG &a){return b< a.f;};
00082 friend bool operator>=(double b, const BG &a){return b>=a.f;};
00083 friend bool operator> (double b, const BG &a){return b> a.f;};
00084 friend bool operator==(double b, const BG &a){return b==a.f;};
00085 friend bool operator!=(double b, const BG &a){return b!=a.f;};
00086
00087
00088 friend BG& operator+=(BG &a, const BG &b);
00089 friend BG& operator-=(BG &a, const BG &b);
00090 friend BG& operator*=(BG &a, const BG &b);
00091 friend BG& operator/=(BG &a, const BG &b);
00092 friend BG& operator+=(BG &a, double b);
00093 friend BG& operator-=(BG &a, double b);
00094 friend BG& operator*=(BG &a, double b);
00095 friend BG& operator/=(BG &a, double b);
00096
00097
00098 BG& operator=(double b);
00099
00100
00101
00102 friend BG sqrt(const BG &a);
00103 friend BG log (const BG &a);
00104 friend BG exp (const BG &a);
00105 BG power(double y) const {BG r = exp(y*log(*this)); return r;}
00106
00107 friend double fabs(const BG &a){return std::fabs(a.f);};
00108
00109 void NRupdate(void);
00110
00111 void display(void);
00112
00113 friend std::ostream& operator<<(std::ostream &os, const BG &a){
00114 os << a.f ;
00115 return os;
00116 }
00117
00118
00119 };
00120
00121 inline void initial_BGarray( BG *v, unsigned n, double a) {
00122 for (unsigned i = 0; i<n; i++) {
00123 v[i] = a;
00124 }
00125 }
00126
00127 }
00128 #endif