如何用c语言解线形方程组

来源:百度知道 编辑:UC知道 时间:2024/05/06 13:04:01
已经高斯消元了。然后采用什么算法?

#include <malloc.h>
#include <math.h>

int gauss(int n,double a[],double b[]) /*数组a、b对应于线性方程组AX=B中的向量A、B*/
{
int i,j,k,*js,is;
double max,t;
js=malloc(n*sizeof(int)); /* 开辟用于记录列交换位置的动态空间 */
for(k=0;k <n-1;k++)
{
max=0.0;
for(i=k;i <n;i++) /* 全选主元 */
for(j=k;j <n;j++)
{
t=fabs(a[i*n+j]);
if(t> max)
max=t,js[k]=j,is=i;
}
if(max+1.0==1.0) /* 如果系数矩阵奇异,就返回相关信息并退出 */
{
free(js);
printf( "\nHas not exclusive result or has not result!\n ");
return(0);
}
else
{
if(js[k]!=k) /* 列交换 */
for(i=0;i <n;i+