我有这个方法返回矩阵三角化例程中使用的值
float **trian(int n, float **Xy)
{
int i,row,col;
float **sign = 1;
for ( i = 0; i < n; i++) {
int max = 0;
for ( row = i; row < n; row++)
if (fabs(Xy[row][i]) > fabs(Xy[max][i]))
max = row;
if (max) {
sign = -sign;
float *tmp = Xy[i];
Xy[i] = Xy[max], Xy[max] = tmp;
}
if (!Xy[i][i]) return 0;
row=0;
for (row = i + 1; row < n; row++) {
float r = Xy[row][i] / Xy[i][i];
if (!r) continue;
for ( col = i; col < n; col ++)
Xy[row][col] -= Xy[i][col] * r;
}
}
return sign;
}
不幸的是得到这个错误
main.c:74:20: error: wrong type argument to unary minus
错误行
sign = -sign;
答案 0 :(得分:1)
这里出了点问题:
float **sign = 1;
....
sign = -sign;
您的意思是使用**sign
代替sign
吗?
也许你只需要这样的东西:
int trian(int n, float **Xy) {
...
int sign = 1;
...
sign = -sign;
...
return sign;
}