Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void GaussPartialSparseMatrix(int n, vector<double> x, vector< vector<double> > a, vector<double> b){
- printf("\n%-35s", "GAUSS PARTIAL FOR SPARSE MATRIX");
- for(int p = 0; p < n; p++){
- // find pivot row and swap
- int max = p; // indeks najwiekszego
- for(int i = p+1; i < n; i++){
- if(abs(a[i][p]) > abs(a[max][p]))
- max = i;
- }
- a[p].swap(a[max]);
- swap(b[p], b[max]);
- // pivot within A and B
- for(int i = p+1; i < n; i++){
- // i wiersz
- // sprawdzenie czy element zerowy jesli tak przejscie do nastepnego wiersza
- if (a[i][p] == 0) continue;
- double alpha = a[i][p]/a[p][p];
- b[i] = b[i] - (alpha * b[p]);
- for(int j = p; j < n; j++){
- a[i][j] = a[i][j] - (alpha * a[p][j]);
- }
- }
- }
- for(int i = n - 1; i >= 0; i--){
- double sum = 0;
- for(int j = i+1; j < n; j++){
- sum += a[i][j] * x[j];
- }
- x[i] = (b[i] - sum)/a[i][i];
- }
- WYNIK = x[0];
- // cout<<"\nThe Solution is : \n";
- // for(int i=0;i<n;i++) {
- // cout<<"\nx("<<i<<") = "<<x[i]<<"\n";
- // }
- cout << ": x[0] = " << WYNIK;
- // cout << "====================\n";
- //getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement