s(i)Рend doРstopРend program mainР!gauss_jordan法的函数Рsubroutine gauss_jordan(a,s,ans,row,width)Рimplicit noneРinteger::row,widthРreal::a(row,width),s(row),ans(row),b(row,width),iР!保存原先的矩阵a及数组BРb=aРans=sР!把B化成对角线矩阵Рcall upper(b,ans,row,width)Рcall lower(b,ans,row,width)Р!求出解Рdo i=1,rowРans(i)=ans(i)/b(i,2)Рend doРreturnРend subroutine gauss_jordanРsubroutine upper(m,s,row,width)Рimplicit noneРinteger::row,widthРreal::m(row,width),s(row)Рinteger::i,jРreal ::eРdo i=1,row -1Рj=i+1Рe=m(j,1)/m(i,2)Рm(j,1:2)=m(j,1:2)-m(i,2:3)*eРs(j)=s(j)-s(i)*eРend doРreturnРend subroutine upperРsubroutine lower(m,s,row,width)Рimplicit noneРinteger::row,widthРreal::m(row,width),s(row)Рinteger::i,jРreal::eРdo i=row,2,-1Рj=i-1Рe=m(j,3)/m(i,2)Рm(j,3)=m(j,3)-m(i,2)*eРs(j)=s(j)-s(i)*EРend doРreturnРend subroutine lower