Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.