float aMatrix[10][11];
float bMatrix[10];
// そのように呼び出されます...
solveMatrix(aMatrix, bMatrix, actualCol);
float* solveMatrix(float aMatrix[][DEFCOLS+1],float bMatrix[DEFCOLS], size_t cols){
std::cout << "\nInside solveMatrix...: " << endl;
size_t N2 = cols;
std::cout << "\N2 is...: " << N2 << endl;
for(size_t p=0; p<N2; p++){
//std::cout << "\nInside 1st for loop...: " << endl;
// find pivot row and swap
int max = p;
for(size_t i=p+1; i<N2; i++){
//std::cout << "\nInside 2nd for loop...: " << endl;
if ( abs(aMatrix[i][p]) > abs(aMatrix[max][p]) ){
max = i;
}
}
//std::cout << "\nJust b4 all the swapping...: " << endl;
float temp[] = { *aMatrix[p] };
*aMatrix[p] = *aMatrix[max];
*aMatrix[max] = *temp;
float t = bMatrix[p];
bMatrix[p] = bMatrix[max];
bMatrix[max] = t;
//std::cout << "\nDone all the swapping...: " << endl;
if ( abs(aMatrix[p][p]) <= MINISCULE) {
//std::cout << "***** Error matrix value too small. Matrix is singular" << endl;
//exit;
}
//std::cout << "\nJust the pivoting...: " << endl;
// Pivot /in A and b
for(size_t i=p+1; i<N2; i++){
//std::cout << "\nInside the 1st pivoting loop...: " << endl;
//std::cout << "\nAbout to do the [aMatrix[p][p]] division in back subst..: " << endl;
float alpha = aMatrix[i][p] / aMatrix[p][p];
bMatrix[i] = alpha * bMatrix[p];
for(size_t j=p; j<N2; j++){
//std::cout << "\nInside the 2nd pivoting loop...: " << endl;
aMatrix[i][j] -= alpha * aMatrix[p][j];
}
}
std::cout << "\nAbout to do the back subst..: " << endl;
// back subst.
float outMatrix[DEFROWS] = {0.0};
for(size_t i=N2-1; i>=0; i--){
std::cout << "\nInside the 1st back subst for loop..: " << endl;
float sum = 0.0;
for(size_t j=i+1; j<N2; j++){
std::cout << "\nInside the 2nd back subst for loop..: " << endl;
sum += aMatrix[i][j] * outMatrix[j];
}
std::cout << "\nAbout to do the [aMatrix[i][i]] division in back subst..: " << endl;
std::cout << "\n*outMatrix[i]: " << outMatrix[i] << endl;
std::cout << "\n( bMatrix[i] - sum ) : " << ( bMatrix[i] - sum ) << endl;
std::cout << "\n****aMatrix[i][i] : " << aMatrix[i][i] << endl;
if (aMatrix[i][i] > 0){
std::cout << "\nDid the division [aMatrix[i][i]] > 0 division in back subst..: " << endl;
std::cout << "\n*outMatrix[i]: " << outMatrix[i] << endl;
std::cout << "\n( bMatrix[i] - sum ) : " << ( bMatrix[i] - sum ) << endl;
std::cout << "\naMatrix[i][i] : " << aMatrix[i][i] << endl;
outMatrix[i] = ( bMatrix[i] - sum ) / aMatrix[i][i];
std::cout << "\nDid the division [aMatrix[i][i]] > 0 division in back subst..DONE: " << endl;
}else {
std::cout << "\nDid the divirion [aMatrix[i][i]] = 0 division in back subst..: " << endl;
outMatrix[i] = 0.0;
std::cout << "\nDid the divirion [aMatrix[i][i]] = 0 division in back subst..DONE: " << endl;
}
std::cout << "\nDid the [aMatrix[i][i]] division in back subst..: " << endl;
}
std::cout << "\nLeft the back subst for loops..: " << endl;
return outMatrix;
}
} // end solveMatrix()
私の問題は、プログラムが実行されているように見えますが、マトリックスの終わりを過ぎて実行されてクラッシュしているように見えることです。さらに、私はいくつかの大きな指数を取得しており、配列にある最大の数値は 1 ~ 10 です。
出力のスクリーンショットを次に示します。切り取りツールから貼り付けられないようです。しかし、問題は「バック置換」が始まった後に始まるようです。どんな助けでも大歓迎です。