/**
* 求矩阵A的逆矩阵Ai
*@param A 源矩阵
*@param Ai 逆矩阵
*@param size 矩阵的大小
*@return 求解成功返回非零值,失败返回零
*/
int InverseMatrix(double **Ai, double **A, int size)
{
int i, j;
double *b, *x;
b = (double*)malloc(sizeof(double)*size);
x = (double*)malloc(sizeof(double)*size);
for (i = 0; i < size; i++)
{
memset(b, 0, sizeof(double)*size);
b[i] = 1;
if (!LinearEquation(A, x, b, size))
{
free(b);
free(x);
return 0;
}
for (j = 0; j < size; j++)
Ai[j][i] = x[j];
}
free(b);
free(x);
return 1;
}