1、清空Label1角度:Label2弧度:Text1txt_jd无定义Text2txt_hd(3)程序代码Private Sub Cmd_jh_Click()Const pi# = 3.14159265358979 定义常量piDim d%, f%, m#, fh%, jdzh%jd = txt_jd.Textfh = Sgn(jd) 获取输入角度的正负号jd = Abs(jd) 取输入角度的绝对值d = Int(jd) 提取度f = Int(jd - d) * 100) 提取分m = (jd - d) * 100 - f) * 100 提取秒jdzh = (d + f / 60 + m / 3
2、600) 得到角度总和,单位为度hd = Format(jd * pi / 180 * fh, 0.000000) 保留6位小数txt_hd.Text = hdEnd SubPrivate Sub Cmd_hj_Click()Dim d%, f%, m#, fh%hd = txt_hd.Textfh = Sgn(hd) 获取输入弧度的正负号jdzh = Abs(hd) * 180 / pi 将弧度转换为角度,单位为度d = Int(jdzh) f = Int(jdzh - d) * 60) m = (jdzh - d) * 60 - f) * 60 jd = Format(d + f / 10
3、0 + m / 10000) * fh, 0.0000得到度.分秒并保留四位小数txt_jd.Text = jdPrivate Sub Cmd_qk_Click()txt_jd.Text = txt_hd.Text = (4)运行结果实验二 矩阵的加、减、乘、转置、求逆根据矩阵的运算方法及规则,只有当两个矩阵是同型矩阵时,这两个矩阵才能进行加法和减法运算。只有当第一个矩阵(左矩阵)的列数等于第二个矩阵(右矩阵)的行数时,两个矩阵才能相乘。矩阵的转置是行变列,列变行。矩阵的求逆:。首先提取矩阵中的数据,再利用调用函数完成矩阵运算。frm_jzys矩阵运算(彭思强)Cmd_jiaA+BCmd_ji
4、anA-BCmd_chengA*BCommand4Cmd_zhuanzhiATCommand5Cmd_qiuniA-1Command6Cmd_qc清除ABLabel3 CTxt_aTxt_bText3Txt_cOption Base 1 数组从1开始Dim A() As DoubleDim B() As DoubleDim C() As Double矩阵相加运算提取数据Private Sub Cmd_jia_Click()Dim i As IntegerDim j As IntegerDim m1 As IntegerDim n1 As IntegerDim m2 As IntegerDim
5、n2 As IntegerDim mystring() As StringDim l() As String 提取矩阵A的数据mystring() = Split(Txt_a.Text, vbCrLf)m1 = UBound(mystring, 1) - LBound(mystring, 1) + 1 获取行数l() = Split(mystring(0), 第一行数据n1 = UBound(l, 1) - LBound(l, 1) + 1 获取列数ReDim A(m1, n1) 重新定义矩阵AFor i = 1 To m1 l() = Split(mystring(i - 1), ) n1
6、= UBound(l, 1) - LBound(l, 1) + 1 For j = 1 To n1 A(i, j) = l(j - 1) Next jNext i提取矩阵B的数据mystring() = Split(Txt_b.Text, vbCrLf)m2 = UBound(mystring, 1) - LBound(mystring, 1) + 1 n2 = UBound(l, 1) - LBound(l, 1) + 1 ReDim B(m2, n2) 重新定义矩阵BFor i = 1 To m2 n2 = UBound(l, 1) - LBound(l, 1) + 1 For j = 1
7、 To n2 B(i, j) = l(j - 1) 获取矩阵BReDim C(m1, n1) 重新定义矩阵CCall madd(A, B, C) 调用矩阵相加的函数Txt_c.Text = Txt_c.Text = Txt_c.Text + Str(C(i, j) + Txt_c.Text = Txt_c.Text + vbCrLf矩阵相减运算提取数据Private Sub Cmd_jian_Click() A(i, j) = l(j - 1) 获取矩阵ACall mcut(A, B, C) 调用矩阵相减的函数矩阵相乘运算提取数据Private Sub Cmd_cheng_Click()ReD
8、im C(m1, n2) Call mmul(A, B, C) 调用矩阵相乘的函数矩阵转置提取数据Private Sub Cmd_zhuanzhi_Click()Dim AT() As DoubleReDim AT(n1, m1) 重新定义矩阵ATCall mtrans(A, AT) 调用矩阵转置的函数For i = 1 To n1 For j = 1 To m1 Txt_c.Text = Txt_c.Text + Str(AT(i, j) + Next i矩阵求逆提取数据Private Sub Cmd_qiuni_Click()重新定义Call MRinv(A) 调用矩阵求逆的函数 Txt_
9、c.Text = Txt_c.Text + Str(A(i, j) + Cmd_qc_Click()事件完成数据的清除Private Sub Cmd_qc_Click()Txt_a.Text = Txt_b.Text = Sub madd(mtxA() As Double, mtxB() As Double, mtxC() As Double) 矩阵相加 Dim i As Integer, j As Integer Dim m As Integer, n As Integer m = UBound(mtxA, 1) - LBound(mtxA, 1) + 1 n = UBound(mtxA,
10、2) - LBound(mtxA, 2) + 1 For i = 1 To m For j = 1 To n mtxC(i, j) = mtxA(i, j) + mtxB(i, j)Sub mcut(mtxA() As Double, mtxB() As Double, mtxC() As Double) 矩阵相减 mtxC(i, j) = mtxA(i, j) - mtxB(i, j)Sub mmul(mtxA() As Double, mtxB() As Double, mtxC() As Double) 矩阵相乘 Dim l As Integer, K As Integer l = UB
11、ound(mtxB, 2) - LBound(mtxB, 2) + 1 For j = 1 To l For K = 1 To n mtxC(i, j) = mtxC(i, j) + mtxA(i, K) * mtxB(K, j) Next KSub mtrans(mtxA() As Double, mtxAT() As Double) 矩阵转置 For i = 1 To n For j = 1 To m mtxAT(i, j) = mtxA(j, i)Function MRinv(mtxA() As Double) As Boolean 矩阵求逆Dim n As Integern = UBo
12、und(mtxA, 1) - LBound(mtxA, 1) + 1ReDim nIs(0 To n) As Integer, nJs(0 To n) As IntegerDim i As Integer, j As Integer, K As IntegerDim D As Double, p As DoubleFor K = 1 To nD = 0#For i = K To n For j = K To n p = Abs(mtxA(i, j) If (p D) Then D = p nIs(K) = i nJs(K) = j End IfNext jIf (D + 1# = 1#) Th
13、en MRinv = False Exit FunctionEnd IfIf (nIs(K) K) Then p = mtxA(K, j) mtxA(K, j) = mtxA(nIs(K), j) mtxA(nIs(K), j) = pIf (nJs(K) p = mtxA(i, K) mtxA(i, K) = mtxA(i, nJs(K) mtxA(i, nJs(K) = pmtxA(K, K) = 1# / mtxA(K, K)For j = 1 To n If (j K) Then mtxA(K, j) = mtxA(K, j) * mtxA(K, K)For i = 1 To n If
14、 (i K) Then mtxA(i, j) = mtxA(i, j) - mtxA(i, K) * mtxA(K, j) K) Then mtxA(i, K) = -mtxA(i, K) * mtxA(K, K)Next KFor K = n To 1 Step -1 If (nJs(K) mtxA(K, j) = mtxA(nJs(K), j) mtxA(nJs(K), j) = p mtxA(i, K) = mtxA(i, nIs(K) mtxA(i, nIs(K) = pMRinv = TrueEnd Function实验三 坐标正反算1.坐标正算已知一点坐标A(XA,YA)、水平距离DAB和坐标方位角AB,求另一点坐标B(XB,YB)。利用角度与弧度的相互转换函数,根据坐标正算公式XB=XA+DAB*Cos(AB),YB=YA+DAB* Sin(AB)计算出B点坐标。窗体、框架等控件属性设置frm_zbzs坐标正算(彭思强)Cmd_js计算
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1