数学
用vb设计一个应用程序完成二元一次方程组的求解仅考虑有唯一求解的情况程序界面:[ ]X+[ ]Y=[ ][ ]X+[ ]Y=[ ]方程组的解为:

2019-05-07

用vb设计一个应用程序完成二元一次方程组的求解
仅考虑有唯一求解的情况
程序界面:
[ ]X+[ ]Y=[ ]
[ ]X+[ ]Y=[ ]
方程组的解为:
优质解答
假设方程的系数均为整数,且方程有解,则如下代码:
结果是以分数表示的,相当准.
Dim D
Sub GongYueShu(ByVal A,ByVal B)
Dim C As Long
If B > A Then
C = B
B = A
A = C
End If
Do
r = A Mod B
If r = 0 Then D = B
A = B
B = r
Loop While r 0
End Sub
Private Sub Command1_Click()
a1 = Text1.Text
b1 = Text2.Text
c1 = Text3.Text
a2 = Text4.Text
b2 = Text5.Text
c2 = Text6.Text
m = b1 * a2 - a1 * b2
n = c1 * a2 - a1 * c2
p = b1 * c2 - c1 * b2
If n Mod m 0 Then
GongYueShu n,m
If n \ m = 0 Then
y = (n Mod m) \ D & "/" & m \ D
Else
y = n \ m & "(" & (n Mod m) \ D & "/" & m \ D & ")"
End If
Else
y = n \ m
End If
If p Mod m 0 Then
GongYueShu p,m
If p \ m = 0 Then
x = (p Mod m) \ D & "/" & m \ D
Else
x = p \ m & "(" & (p Mod m) \ D & "/" & m \ D & ")"
End If
Else
x = p \ m
End If
Label5.Caption = "x=" & x
Label6.Caption = "y=" & y
End Sub
假设方程的系数均为整数,且方程有解,则如下代码:
结果是以分数表示的,相当准.
Dim D
Sub GongYueShu(ByVal A,ByVal B)
Dim C As Long
If B > A Then
C = B
B = A
A = C
End If
Do
r = A Mod B
If r = 0 Then D = B
A = B
B = r
Loop While r 0
End Sub
Private Sub Command1_Click()
a1 = Text1.Text
b1 = Text2.Text
c1 = Text3.Text
a2 = Text4.Text
b2 = Text5.Text
c2 = Text6.Text
m = b1 * a2 - a1 * b2
n = c1 * a2 - a1 * c2
p = b1 * c2 - c1 * b2
If n Mod m 0 Then
GongYueShu n,m
If n \ m = 0 Then
y = (n Mod m) \ D & "/" & m \ D
Else
y = n \ m & "(" & (n Mod m) \ D & "/" & m \ D & ")"
End If
Else
y = n \ m
End If
If p Mod m 0 Then
GongYueShu p,m
If p \ m = 0 Then
x = (p Mod m) \ D & "/" & m \ D
Else
x = p \ m & "(" & (p Mod m) \ D & "/" & m \ D & ")"
End If
Else
x = p \ m
End If
Label5.Caption = "x=" & x
Label6.Caption = "y=" & y
End Sub
相关问答