I was wondering if anyone could give me some pointers. I'm trying to come up with a matrix class so that I can do a class assignment that has me go through 3 dif iterative methods that work off of matrices (Jacobi, Gauss-seidel, SOR with user input for the omega value). I'm sure there are algorithms out there already for those three so that shouldn't be a problem.

What my issues are trying to finish this matrix class so that I can achieve the following: Generate a random, diagonally dominant matrix problem and save to file A and b into separate files, Load a matrix of size nxn from a file named A.txt, Load a vector of size n from a file named b.txt, then solve the problem Ax=b using the 3 methods above.

matrix.h

#ifndef MATRIX_H_INCLUDED #define MATRIX_H_INCLUDED class matrix { public: matrix(int n); void gensol(); void genb(); void display(); private: int N; double ** A; double *Sol; double *b; }; #endif // MATRIX_H_INCLUDED

matrix.cpp

#include <cmath> #include <stdlib.h> #include <iomanip> #include <iostream> #include "matrix.h" using namespace std; matrix::matrix(int n) { double sum=0; N=n; A = new double * [N]; Sol = new double [N]; b = new double [N]; gensol(); for (int i=0; i<N; i++) {A[i]= new double [N];} int r; for(int i=0; i<N; i++) for(int j=0; j<N; j++) {A[i][j]=( (double) (rand()%10000) )/100.0; r=rand()%2; if(r==1){A[i][j]=A[i][j]*-1;} } //enforcing diagonal dominance for (int row=0; row<N; row++) { for(int col=0; col<N; col++) {if(row!=col) {sum= sum+abs(A[row][col]);} } A[row][row]=sum+100; sum=0; } genb(); } void matrix::display() { for(int i=0; i<N; i++) {for(int j=0; j<N; j++) {cout<<setw(10)<<A[i][j];} cout<<setw(15)<<Sol[i]; cout<<setw(15)<<b[i]; cout<<endl; } } void matrix::gensol() { int r; for(int row=0; row<N; row++) {Sol[row]=( (double) (rand()%10000) )/100.0; r=rand()%2; if(r==1){Sol[row]=Sol[row]*-1;} } } void matrix::genb() { double temp = 0; for(int row=0; row<N; row++) { for(int col=0; col<N; col++) { temp=(A[row][col]*Sol[col])+temp; } b[row]=temp; temp=0.0; } }

main.cpp

Not developed yet

I'm trying to just get this thing to be created first.

*EDIT*

Do you guys think I can follow this and then just add my functions that are already declared to it to get everything in order?

http://www.cs.umb.ed...pts/cs410-7.pdf

This post has been edited by **R2B Boondocks**: 12 February 2014 - 07:57 AM