【vfp开源代码栏目提醒】:网学会员为需要vfp开源代码的朋友们搜集整理了COMARRAYDemo.PRG相关资料,希望对各位网友有所帮助!
DEFINE CLASS COMARRAYDemo AS session OLEPUBLIC
*-------------------------------------------------------------------------
*-- The array is now correctly written strongly typed to the type library.
*-- The @ indicates that in the type library the array is passed ByRef.
*-------------------------------------------------------------------------
FUNCTION Determinant(mat[] AS Double @) AS Double
*-------------------------------------------------------------------------
LOCAL i as Integer
LOCAL j as Integer
LOCAL k as integer
LOCAL factor as Double
LOCAL temp as Double
LOCAL det as Double
dim = ALEN(mat,1)
det = 1.0
&& do the elimination
FOR i = 1 TO dim-1
&& if the main diagonal value is zero
&& re-sort the array
IF (mat(i,i) = 0) THEN
FOR j = i+1 to dim
IF (mat(j,i) <> 0) THEN
FOR k = 1 TO dim
temp = mat(i,k)
mat(i,k) = mat(j,k)
mat(j,k) = temp
NEXT
&& For Gauss-Jordan Elimination,
&& if we do a switch, the determinant
&& switches sign.
det = -det
EXIT
ENDIF
NEXT
ENDIF
&& if after the resorting, the value is still zero }
&& then the determinant is definitely zero }
IF (mat(i,i) = 0) THEN
gauss = 0
EXIT
ENDIF
&& eliminates the lower rows to achieve triangular zeroes
FOR j = i+1 TO dim
IF (mat(j,i) <> 0) THEN
factor = (mat(j,i) * 1.0) / mat(i,i)
FOR k = i TO dim
mat(j,k) = mat(j,k) - factor * mat(i,k)
&& {2}
NEXT
&& {1}
ENDIF
NEXT
NEXT
&& calculates the main diagonal }
FOR i = 1 TO dim
det = det * mat(i,i)
NEXT
RETURN det
ENDFUNC
ENDDEFINE
上一篇:
ColumnChartListener.prg
下一篇:
关于大学英语教学