void forward_elimination(Matrix A){
// 前進消去のコードだけを書くこと
}
void backward_substitution(Matrix A){
// 後退代入のコードだけを書くこと
}
// ガウス消去法を使って連立方程式を解く
void gauss_elimination(Matrix A){
forward_elimination(A); // 前進消去
backward_substitution(A); // 後退代入
}
Z:\compmech\ex7>7_1.exe A4_mat.csv b4_vec.csv 2.000 1.000 3.000 3.000 | 35.000 3.000 1.000 0.000 2.000 | 9.000 1.000 -2.000 3.000 5.000 | 32.000 1.000 1.000 -3.000 1.000 | -23.000 ----- Solution by the Gauss Jordan method ----- Changed row 1 and row 2. 3.000 1.000 0.000 2.000 | 9.000 2.000 1.000 3.000 3.000 | 35.000 1.000 -2.000 3.000 5.000 | 32.000 1.000 1.000 -3.000 1.000 | -23.000 ... ----- Answers ----- x[1] = 1.000 x[2] = 2.000 x[3] = 3.000 x[4] = 4.000 ----- Solution by the Gauss Elimination method ----- < Forward elimination > Changed row 1 and row 2. 3.000 1.000 0.000 2.000 | 9.000 2.000 1.000 3.000 3.000 | 35.000 1.000 -2.000 3.000 5.000 | 32.000 1.000 1.000 -3.000 1.000 | -23.000 ... ----- Answers ----- x[1] = 1.000 x[2] = 2.000 x[3] = 3.000 x[4] = 4.000
// time_test.cpp
#include <stdio.h>
#include <windows.h>
// ↓ clock 関数を用いて時間計測する人向け
// #include <time.h>
int main(void) {
DWORD time1, time2;
// ↓ clock 関数を用いて時間計測する人向け
// clock_t time1, time2;
float a = 0;
time1 = timeGetTime();
// ↓ clock 関数を用いて時間計測する人向け
// time1 = clock();
// 足し算を1億回繰り返す
for (int i=0;i<100000000;++i) {
a += 0.001;
}
time2 = timeGetTime();
// ↓ clock 関数を用いて時間計測する人向け
// time2 = clock();
printf("Calculation time : %ld [ms]\n", time2-time1);
// ↓ clock 関数を用いて時間計測する人向け
// printf("Calculation time : %f [s]\n", (double)(time2-time1)/CLOCKS_PER_SEC);
return 0;
}
Z:\compmech\ex7>7_2.exe A100_mat.csv b100_vec.csv Number of Repetitions : 1000 ----- Gauss Jordan method ----- Calculation time : 636 [ms] ----- Gauss Elimination method ----- Calculation time : 407 [ms]