Skip to content

Instantly share code, notes, and snippets.

@aximov
Created July 6, 2018 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aximov/877dac7c3089951afcbadad7885fb603 to your computer and use it in GitHub Desktop.
Save aximov/877dac7c3089951afcbadad7885fb603 to your computer and use it in GitHub Desktop.
Gauss-Jordan 掃き出し法
#include <bits/stdc++.h>
using namespace std;
void printmatrix(double a[10][11], int n) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n+1; ++j) {
cout << a[i][j] << " ";
}
cout << endl;
}
cout << endl;
}
void gaussjordan(double a[10][11], int n) {
for (int k = 0; k < n; ++k) {
printmatrix(a, n);
double w1 = a[k][k];
for(int j = k; j <= n; ++j) {
a[k][j] = a[k][j]/w1;
}
for (int i = 0; i <= n; ++i) {
double w2 = a[i][k];
if (i != k) {
for (int j = k; j <= n; ++j) {
a[i][j] = a[i][j] - w2*a[k][j];
}
}
}
}
}
int main() {
double a[10][11] = {
{ 2, -2, 3, 1, },
{ 1, 1, -6, -1, },
{ 3, -2, 4, 4, },
};
int n = 3;
gaussjordan(a, n);
printmatrix(a, n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment