欢迎来到天天文库
浏览记录
ID:35386995
大小:60.84 KB
页数:7页
时间:2019-03-24
《求解线性方程组的lu分解法》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、原[数值算法]求解线性方程组的LU分解法由于求解三解方程较易,所以,考虑将系数矩阵A分解成两个三角矩阵的乘积,即:A=LU的形式其屮,L为下三解矩阵,U为上三解矩阵,则线性方程组:Ax=b可改写为LUx=b令Ux=y得Ly=b然后,用前代方法求Ly二b得列矩阵y,再用冋代方法求Ux二b,得到的列矩阵x即为所求的线性方程组的解.分解的细节请参考相应的数值算法书籍,这里就不做过细的解释了.首先是一个对下三解矩阵的前代方法,很简单的:voiddownTriangleMethod(Type**matrixArr,Type*bList,Type*xAnsList
2、,intlen){inti=0,j=0;doublee=0.0001;/*precisecontroller*/TypetmpSum;Type*tmpBList;/*■一assertion■一*/assertF(iTiatrixArr!=NULL,"inupAngleMethod,matrixArrisNULL'r);assertF(bList!=NULL,"inupAngleMethod,bListisNULLn);assertF(xAnsList!=NULL,ninupAngleMethod,xAnsListisNULLS');/*mcma
3、pply*/tmpBList=(Type*)malloc(sizeof(Type)*len);for(i=0;i=e,"inupAngleMethod,matrixArr[i][i
4、hasvalueclosedto0u);/*datainitialiate*/tmpBList[O]=tmpBList[O]/matrixArr[O][0];/*Getthefirsta
5、nswer*/i=l;/*Corepartoftheuptrianglemethod*/while(i6、i11j]*tmpBList[j];tmpBList[i]=(tmpBList[iJ-tmpSum)/matrixArr[i][il;i++;}/*copytoanswer*/for(i=0;i7、repartoftheLUPationMethod.*/voidLUPationMethod(Type**matrixArr,Type*bList.Type*xAnsList,intlen){/*Corethinkofthisalgorithm:matrix_L*yAnsList=bList;matrix_U*xAnsList=yAnsList;引Type**matrixJL,**matrix_U;/^ThecoretwomatrixobjectoftheLUmethod.*/Type*yAnsList;intij,k;/*iteratornum*/i8、nti2,j2;Typesum;/*thetemptweendata*//*inputassertion*/assertF(matrixArr!=NULL/,inLUPationMethod,matrixArrisNULL");assertF(bList!=NULL,"inLUPationMethod,bListisNULLu);assertF(xAnsList!=NULL,,'inLUPationMethod,xAnsListisNULL”);/*memoryapply*/matrix_L=(Type**)malloc(sizeof(Ty9、pe*)*len);matrix_U=(Type**)malloc(sizeof(Type*)*len);for(i=0;i10、L,ninLUPationMethod,matrix_LisNULLH);assertF(
6、i11j]*tmpBList[j];tmpBList[i]=(tmpBList[iJ-tmpSum)/matrixArr[i][il;i++;}/*copytoanswer*/for(i=0;i7、repartoftheLUPationMethod.*/voidLUPationMethod(Type**matrixArr,Type*bList.Type*xAnsList,intlen){/*Corethinkofthisalgorithm:matrix_L*yAnsList=bList;matrix_U*xAnsList=yAnsList;引Type**matrixJL,**matrix_U;/^ThecoretwomatrixobjectoftheLUmethod.*/Type*yAnsList;intij,k;/*iteratornum*/i8、nti2,j2;Typesum;/*thetemptweendata*//*inputassertion*/assertF(matrixArr!=NULL/,inLUPationMethod,matrixArrisNULL");assertF(bList!=NULL,"inLUPationMethod,bListisNULLu);assertF(xAnsList!=NULL,,'inLUPationMethod,xAnsListisNULL”);/*memoryapply*/matrix_L=(Type**)malloc(sizeof(Ty9、pe*)*len);matrix_U=(Type**)malloc(sizeof(Type*)*len);for(i=0;i10、L,ninLUPationMethod,matrix_LisNULLH);assertF(
7、repartoftheLUPationMethod.*/voidLUPationMethod(Type**matrixArr,Type*bList.Type*xAnsList,intlen){/*Corethinkofthisalgorithm:matrix_L*yAnsList=bList;matrix_U*xAnsList=yAnsList;引Type**matrixJL,**matrix_U;/^ThecoretwomatrixobjectoftheLUmethod.*/Type*yAnsList;intij,k;/*iteratornum*/i
8、nti2,j2;Typesum;/*thetemptweendata*//*inputassertion*/assertF(matrixArr!=NULL/,inLUPationMethod,matrixArrisNULL");assertF(bList!=NULL,"inLUPationMethod,bListisNULLu);assertF(xAnsList!=NULL,,'inLUPationMethod,xAnsListisNULL”);/*memoryapply*/matrix_L=(Type**)malloc(sizeof(Ty
9、pe*)*len);matrix_U=(Type**)malloc(sizeof(Type*)*len);for(i=0;i10、L,ninLUPationMethod,matrix_LisNULLH);assertF(
10、L,ninLUPationMethod,matrix_LisNULLH);assertF(
此文档下载收益归作者所有