//回代,求解线性方程组的结果(2)
// 找到最大的列主元 for(j = i; j < size; j++) { if(p[j][i] > largest) { largest = p[j][i]; swap_index = j; } } //如果最大列主元不在子块的第一行,那么进行交换 if(i != swap_index) { double temp = 0; for(j = 0; j < size; j++) { temp = p[i][j]; p[i][j] = p[swap_index][j]; p[swap_index][j] = temp; } temp = B[i]; B[i] = B[swap_index]; B[swap_index] = temp; } //进行消元 double mi = 1.0; for(j = i + 1; j < size; j++) { mi = p[j][i]/p[i][i]; for(int k = i; k < size; k++) { p[j][k] = p[j][k] - mi * p[i][k]; } B[j] = B[j] - mi * B[i]; } } 相关资料 |