所以我正在研究一个有两个部分的问题。我确实在以下帮助下完成了第一部分:这个有用的论坛。一些机构已经尝试解决问题的第一部分,我拿走了他们的代码。
问题:
- 在 Maple 中编写一个 proc(这里我将其命名为“reduced”),用于计算矩阵的简化梯形形式。
- 编写一个使用“reduced”计算矩阵逆的过程。
第一部分的代码(代码经过测试,我声称它运行正确)
multiplikation:= proc(
m::posint,
a::depends(And(posint, satisfies(a-> a <= m))),
b::And({float, rational}, Not(identical(0,0.)))
)
Matrix((m,m), (i,j)-> `if`(i=j, `if`(i=a, b, 1), 0))
end proc:
addition:= proc(
m::posint,
a::depends(And(posint, satisfies(a-> a <= m))),
b::depends(And(posint, satisfies(b-> b <= m))),
c::And({float, rational}, Not(identical(0,0.)))
)
Matrix((m,m), (i,j)-> `if`(i=a and j=b, c, `if`(i=j, 1, 0)))
end proc:
perm:= proc(
m::posint,
a::depends(And(posint, satisfies(a-> a <= m))),
b::depends(And(posint, satisfies(b-> b <= m and a<>b)))
)
Matrix((m,m), (i,j)-> `if`({i,j}={a,b} or i=j and not i in {a,b}, 1, 0))
end proc:
和主要过程:
reduced:= proc(B::Matrix)
uses LA= LinearAlgebra;
local
M:= B, l:= 1, #l is current column.
m:= LA:-RowDimension(M), n:= LA:-ColumnDimension(M), i, j
;
for i to m do #going through every row item
#l needs to be less than column number n.
if n < l then return M end if;
j:= i; #Initialize current row number.
while M[j,l]=0 do #Search for 1st row item <> 0.
j:= j+1;
if m < j then #End of row: Go to next column.
j:= i;
l:= l+1;
if n < l then return M fi #end of column and row
end if
end do;
if j<>i then M:= perm(m,j,i).M end if; #Permute rows j and i
#Multiply row i with 1/M[i,l], if it's not 0.
if M[i,l] <> 0 then M:= multiplikation(m,i,1/M[i,l]).M fi;
#Subtract each row j with row i for M[j,l]-times.
for j to m do if j<>i then M:= addition(m,j,i,-M[j,l]).M fi od;
l:= l+1 #Increase l by 1; next iteration i increase either.
end do;
return M
end proc:
如果您需要有关上述代码的任何其他信息,我会解释更多。
对于第二部分,我正在考虑使用高斯乔丹算法,但我有一个问题:我不能使用单位矩阵作为“减少”中的参数。因为它在行和列中有 0。
您知道如何在我的 proc 的帮助下实现 Gauss Jordan 算法:减少吗?