#include #include #include using namespace std; class STMatrix { private: enum {normal, upper, lower} state; int n; double* stm; public: STMatrix(int n) { this->n = n; stm = new double[n*2-1]; for (int i=0; irow) return 0; if (state == upper && col row+1) { return 0; } if (col == row) return stm[row]; else return stm[n+col]; } void setElement(int row, int col, double ele) { if (col == row+1) { col--; //adjust for symmetricity row++; } if (col < row-1 || col > row+1) { cerr << "trying to set an off-diagonal element" << endl; return; //can't happen, but if it does let's not crash } if (col == row) stm[row] = ele; else stm[n+col] = ele; } void eliminate() { for (int k=0; k=0 && j=0; i--) b[i] = (b[i]-m.getElement(i, i+1)*b[i+1])/m.getElement(i, i); } double BVP(int k, int which, double alpha, double beta) { int n = (int)pow(2, k); double h = 1/((double)n+1); STMatrix m(n); double* b = new double[n]; for (int i=0; imaxdiff) maxdiff = diff; } delete b; return maxdiff; } int main(int argc, char** argv) { cout << setprecision(15); cout << "a)\tk\t||e||_inf" << endl; for (int k=1; k<=16; k++) cout << "\t" << k << "\t" << BVP(k, 0, 2, 3) << endl; cout << endl; cout << "b)\tk\t||e||_inf" << endl; for (int k=1; k<=16; k++) cout << "\t" << k << "\t" << BVP(k, 1, 1, 0) << endl; return 0; }