112 对称正定矩阵的Cholesky分解 1.功能 分解对称正定矩阵A=LLT,其中L为下三角阵,LT是L的转置. 2.算法简介 由A=LLT,用矩阵乘法并比较两边矩阵的元素,可导出算式。对K=1,2,3…,n LKK=(AKK-ΣI=1k-1L2KI)1/2 LJK=(AJK-ΣI=1k-1LJILIK)/LKK,j=k+1,k+2,…,n. 3. 使用说明 输入参数 N 整变量,方阵的阶数。 A(N,N) N×N个元素的二维数组,按行存放A的元素. 输出参数 W 标志: W=0,A 对称正定,分解为A=LLT;W=1,说明A对称但非正定,不能作Cholesky分解。 L(N,N) 下三角阵。
10 '************************************** ' 20 '* 112 对称正定矩阵的Cholesky分解 *' 30 '************************************** ' 40 INPUT "N="; N 50 DIM A(N, N) 60 PRINT TAB(3); "EXAMPLE"; TAB(8); "JUZHEN A": PRINT 70 FOR I = 1 TO N 80 FOR J = 1 TO N 90 READ A(I, J): PRINT USING "###.#"; A(I, J); 100 NEXT J 110 PRINT 120 NEXT I 130 PRINT : GOSUB 300 140 PRINT TAB(5); "W="; W: PRINT "" 150 IF W = 1 THEN 250 160 PRINT TAB(15); "JUZHEN L" 170 FOR I = 1 TO N 180 FOR J = 1 TO I 190 PRINT USING "##.######"; A(I, J); : PRINT " "; 200 NEXT J 210 PRINT 220 NEXT I 230 DATA 1,2,1,-3,2,5,0,-5,1,0,14,1,-3,-5,1,15 240 DATA 250 END 300 'ZI CHENG XU' 310 IF A(1, 1) <= 0 THEN 410 320 A(1, 1) = SQR(A(1, 1)) 330 FOR I = 2 TO N 340 A(I, 1) = A(I, 1) / A(1, 1) 350 NEXT I 360 FOR K = 2 TO N 370 FOR J = 1 TO K - 1 380 A(K, K) = A(K, K) - A(K, J) ^ 2 390 NEXT J 400 IF A(K, K) > 0 THEN 430 410 W = 1 420 GOTO 530 430 A(K, K) = SQR(A(K, K)) 440 IF K = N THEN 530 450 FOR I = K + 1 TO N 460 FOR J = 1 TO K - 1 470 A(I, K) = A(I, K) - A(I, J) * A(K, J) 480 NEXT J 490 A(I, K) = A(I, K) / A(K, K) 500 NEXT I 510 NEXT K 520 W = 0 530 RETURN 例题 矩阵A 1.0 2.0 1.0 -3.0 2.0 5.0 0.0 -5.0 1.0 0.0 14.0 1.0 -3.0 -5.0 1.0 15.0
W=0 矩阵l 1. 00 2. 00 1. 00 1. 00 -2. 00 3. 00 -3. 00 1. 00 2. 00 1. 00