给了源代码都看不懂,我看你这样学习,做一万道题都是白做。首先你知道矩阵乘法手工怎么做没有?知道的话,不可能看不懂的。其实,从你问过正弦又继续问余弦来看,证明你根本没有从正弦那个题目中学到任何东西,说白学没有冤枉你的。
[ 本帖最后由 TonyDeng 于 2012-1-7 22:02 编辑 ]
[ 本帖最后由 TonyDeng 于 2012-1-7 22:02 编辑 ]
授人以渔,不授人以鱼。
SET DEFAULT TO SYS(2023) SET CONFIRM ON SET DECIMALS TO 4 CLEAR ALL CLOSE DATABASES ALL goForm = CREATEOBJECT("C_Form") goForm.Show READ EVENTS CLOSE DATABASES ALL CLEAR ALL SET DEFAULT TO RETURN PROCEDURE CreateMatrixTable(tcTableName AS Character, tnRows AS Integer, tnCols AS Integer) LOCAL lcString AS Character LOCAL lnRow AS Interger, lnColumn AS Integer lcString = "(R C(3), " FOR lnColumn = 1 TO tnCols lcString = lcString + "C" + PADL(lnColumn, 2, '0') + " N(10.4)" + IIF(lnColumn < tnCols, ", ", ")") NEXT CREATE TABLE (tcTableName) FREE &lcString SELECT (tcTableName) FOR lnRow = 1 TO tnRows APPEND BLANK REPLACE R WITH "R" + PADL(lnRow, 2, '0') NEXT USE IN (tcTableName) ENDPROC PROCEDURE ExportToArray(tcTable AS Character, taArray[]) LOCAL i AS Integer, j AS Integer GOTO TOP IN (tcTable) i = 1 DO WHILE !EOF(tcTable) FOR j = 2 TO FCOUNT(tcTable) taArray[i,j-1] = EVALUATE(tcTable + "." + FIELD(j, tcTable)) NEXT SKIP IN (tcTable) i = i + 1 IF !EOF(tcTable) DIMENSION taArray[i,FCOUNT(tcTable)-1] ENDIF ENDDO ENDPROC PROCEDURE Do_Matrix_Multiplication(tcMatrixA AS Character, tcMatrixB AS Character, tcResult AS Character) LOCAL arrayA[1,FCOUNT(tcMatrixA)-1], arrayB[1,FCOUNT(tcMatrixB)-1] ExportToArray(tcMatrixA, @arrayA) ExportToArray(tcMatrixB, @arrayB) LOCAL i, j, k SELECT (tcResult) LOCAL lcField AS Character LOCAL arrayC[ALEN(arrayA,1),ALEN(arrayB,2)] FOR i = 1 TO ALEN(arrayC,1) FOR j = 1 TO ALEN(arrayC,2) arrayC[i,j] = 0.0 FOR k = 1 TO ALEN(arrayA,2) arrayC[i,j] = arrayC[i,j] + arrayA[i,k] * arrayB[k,j] NEXT GOTO i IN (tcResult) lcField = tcResult + "." + FIELD(j + 1, tcResult) REPLACE (lcField) WITH arrayC[i,j] IN (tcResult) NEXT NEXT ENDPROC DEFINE CLASS C_Form AS Form Caption = "矩阵乘积" ControlBox = .F. BorderStyle = 1 KeyPreview = .T. Width = 800 Height = 600 ShowTips = .T. AutoCenter = .T. ADD OBJECT cntMatrix1 AS C_GetMatrix WITH MatrixName = "矩阵 A", MatrixDBF = "M1" ADD OBJECT cntMatrix2 AS C_GetMatrix WITH MatrixName = "矩阵 B", MatrixDBF = "M2" ADD OBJECT cmdCalculation AS CommandButton WITH Caption = "运算", Height = 25, Width = 60 ADD OBJECT cmdExit AS CommandButton WITH Caption = "结束", Height = 25, Width = 60, ToolTipText = "按Esc键也可结束程序" PROCEDURE Activate WITH ThisForm.cmdCalculation .Top = ThisForm.Height - .Height - 5 .Left = 5 ENDWITH WITH ThisForm.cmdExit .Top = ThisForm.cmdCalculation.Top .Left = ThisForm.cmdCalculation.Left + ThisForm.cmdCalculation.Width ENDWITH WITH Top = 5 .Left = 5 .Height = (ThisForm.cmdCalculation.Top - .Top) / 2 - 5 .Width = 300 ENDWITH WITH Top = Top + + 5 .Left = 5 .Height = ThisForm.cmdCalculation.Top - .Top - 5 .Width = 300 ENDWITH ENDPROC PROCEDURE Destroy CLEAR EVENTS ENDPROC #DEFINE K_ESC 27 PROCEDURE KeyPress(tnKeyCode AS Integer, tnShiftAltCtrl AS Integer) IF tnKeyCode == K_ESC RELEASE ThisForm ENDIF ENDPROC #UNDEFINE K_ESC PROCEDURE cmdCalculation.Click LOCAL lcResultName AS Character lcResultName = "Result" WITH ThisForm IF (.cntMatrix1.Text1.Value > 0) .AND. (.cntMatrix1.Text2.Value > 0) .AND. (.cntMatrix2.Text1.Value > 0) .AND. (.cntMatrix2.Text2.Value > 0) IF .cntMatrix1.Text2.Value == .cntMatrix2.Text1.Value IF VARTYPE(.lblResult) != "O" .AddObject("lblResult", "Label") WITH .lblResult .Caption = "矩阵 AB" .FontSize = 12 .FontBold = .T. .AutoSize = .T. .Top = 5 .Left = Left + + 5 .Visible = .T. ENDWITH ENDIF CreateMatrixTable(lcResultName, .cntMatrix1.Text1.Value, .cntMatrix2.Text2.Value) IF USED(lcResultName) USE IN (lcResultName) ENDIF USE (lcResultName) EXCLUSIVE IN 0 Do_Matrix_Multiplication(ALLTRIM(.cntMatrix1.MatrixDBF), ALLTRIM(.cntMatrix2.MatrixDBF), lcResultName) SELECT (lcResultName) GOTO TOP IF VARTYPE(.grdResult) == "O" .RemoveObject("grdResult") ENDIF .AddObject("grdResult", "MatrixGrid") WITH .grdResult .Set_Data(lcResultName) .ReadOnly = .T. .Top = ThisForm.lblResult.Top + ThisForm.lblResult.Height + 5 .Left = ThisForm.lblResult.Left .Height = ThisForm.cmdCalculation.Top - .Top - 5 .Width = ThisForm.Width - .Left - 5 .Visible = .T. ENDWITH ELSE MESSAGEBOX("两矩阵的行列数不符合乘法运算条件!", 16, .Caption) ENDIF ELSE MESSAGEBOX("数据未输入完毕,无法运算!", 16, .Caption) ENDIF ENDWITH ENDPROC PROCEDURE cmdExit.Click RELEASE ThisForm ENDPROC ENDDEFINE DEFINE CLASS MatrixGrid AS Grid DeleteMark = .T. RecordSourceType = 1 PROCEDURE Set_Data(tcAlias AS Character ) LOCAL lnColumn AS Integer WITH This .RecordSource = tcAlias .ColumnCount = FCOUNT(tcAlias) FOR lnColumn = 1 TO .ColumnCount WITH .Columns(lnColumn) WITH .Header1 .Caption = IIF(lnColumn > 1, FIELD(lnColumn), "") .FontBold = .T. .Alignment = 2 ENDWITH .ControlSource = tcAlias + "." + FIELD(lnColumn) IF lnColumn > 1 .InputMask = "99999.9999" ELSE .Width = 40 .FontBold = .T. .Alignment = 2 .Enabled = .F. ENDIF ENDWITH NEXT ENDWITH ENDPROC ENDDEFINE DEFINE CLASS C_GetMatrix AS Container MatrixName = "" MatrixDBF = "" ADD OBJECT lblMatrixName AS Label WITH Height = 25, AutoSize = .T., FontSize = 12, FontBold = .T. ADD OBJECT Label1 AS Label WITH Caption = "行数: ", Height = 25, Width = 40, Alignment = 1 ADD OBJECT Text1 AS TextBox WITH Value = 0, Height = 25, Width = 40, InputMask = "99", SelectOnEntry = .T. ADD OBJECT Label2 AS Label WITH Caption = "列数: ", Height = 25, Width = 40, Alignment = 1 ADD OBJECT Text2 AS TextBox WITH Value = 0, Height = 25, Width = 40, InputMask = "99", SelectOnEntry = .T. PROCEDURE MatrixName_Assign(tcName AS Character) This.MatrixName = ALLTRIM(tcName) This.lblMatrixName.Caption = This.MatrixName ENDPROC PROCEDURE Init WITH This.lblMatrixName .Caption = This.MatrixName .Top = 5 .Left = 5 ENDWITH WITH This.Label1 .Top = 40 .Left = 5 ENDWITH WITH This.Text1 .Top = This.Label1.Top .Left = This.Label1.Left + This.Label1.Width ENDWITH WITH This.Label2 .Top = This.Label1.Top .Left = This.Text1.Left + This.Text1.Width + 5 ENDWITH WITH This.Text2 .Top = This.Label2.Top .Left = This.Label2.Left + This.Label2.Width ENDWITH ENDPROC PROCEDURE Text1.Valid IF This.Value > 0 This.Parent.InputData ELSE IF This.Value < 0 RETURN .F. ENDIF ENDIF ENDPROC PROCEDURE Text2.Valid IF This.Value > 0 This.Parent.InputData ELSE IF This.Value < 0 RETURN .F. ENDIF ENDIF ENDPROC PROCEDURE InputData LOCAL lcAlias AS Character LOCAL lnRow AS Integer, lnColumn AS Integer LOCAL lcString AS Character IF (This.Text1.Value <= 0) .OR. (This.Text2.Value <= 0) RETURN ENDIF lcAlias = ALLTRIM(This.MatrixDBF) IF USED(lcAlias) USE IN (lcAlias) ENDIF CreateMatrixTable(lcAlias, This.Text1.Value, This.Text2.Value) USE (lcAlias) EXCLUSIVE IN 0 SELECT (lcAlias) GOTO TOP WITH This IF VARTYPE(This.Grid1) == "O" .RemoveObject("Grid1") ENDIF .AddObject("Grid1", "MatrixGrid") WITH .Grid1 .Set_Data(lcAlias) .Top = This.Label2.Top + This.Label2.Height + 5 .Left = 5 .Height = This.Height - .Top - 5 .Width = This.Width - .Left - 5 .Visible = .T. ENDWITH ENDWITH ENDPROC ENDDEFINE