[数值算法]线性方程组的求解---迭代法小结

[数值算法]线性方程组的求解---迭代法小结.

                                                       

                                             by EmilMatthew 05/9/08

当迭代法做多了之后,便感受到这种思想的好用了,今天再次实现用迭代法求解问题,感觉轻松了不少。

       当某个关于x的迭代式xk=fi(xk_1)保持收敛时,则可利迭代来求出最后的结果,直到满足精度要求为止.

       对于线性方程组的求解中迭代法的应用亦是如此,当矩阵的规模大于100*100时,迭代法的优势就突现出来了.

       1) Jacobi

对于线性方程组,可以很方便的对第i行中的元素xi用该行中的其余x来表示,

:

Xi_k+1=1/aii*(bi-sum(aij*Xj_k&&j1=i))

在数学上可以证明它满足迭代条件,所以,这便有了第一个求线性方程组的迭代算法:

Jacobi算法

/*

JacobiMethod, coded by EmilMathew 05/9/8, you can modify and use these code as you wish , but there is no guarantee that it can fit all you need.

*/

/*main aid function,to determine the end of the iterator*/

int preciseReached(Type* xList1,Type* xList2,int len,Type precise)

{

       int i=0;

       int flag;

       assertF(xList1!=NULL,"in preciseReached,xList1 is NULL/n");

       assertF(xList2!=NULL,"in preciseReached,xList2 is NULL/n");

      

       flag=1;

       for(i=0;i<len;i++)

              if(fabs(xList1[i]-xList2[i])>precise)

              {

                     flag=0;

                     break;

              }

       return flag;

}

 

 

void JacobiMethod(Type** inMatrixArr,Type* bList,Type* xAnsList,Type precise,int size,

FILE* outputFile)

{

      

       int iteratorNum;

       int i=0,j=0;

       Type sum=0;

       Type* tmpXList;

      

       /*pointer data assertion*/

       assertF(inMatrixArr!=NULL,"in JacobiMethod,matrixArr is NULL/n");

       assertF(bList!=NULL,"in JacobiMethod,bList is NULL/n");

       assertF(xAnsList!=NULL,"in JacobiMethod,xAnsList is NULL/n");

      

       tmpXList=(Type*)malloc(sizeof(Type)*size);

       assertF(tmpXList!=NULL,"in JacobiMethod,tmpXList is NULL/n");

      

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值