主题:vb编程解二元一次方程组的算法
52vb
[专家分:0] 发布于 2011-10-03 16:22:00
论坛内的各位高手,你们好!本人想请教你们这样一个问题,那就是如何用VB编程算法来解二元一次的方程组,要求是结果要符合代数算法的值,谢谢,别和说一些线性方程,俺就是一个高中生,没啥文化
回复列表 (共1个回复)
沙发
老大徒伤悲 [专家分:29120] 发布于 2011-10-08 09:37:00
不知道你说的“要求是结果要符合代数算法的值”是啥意思,按我的笨想,做了一段代码。
界面:第一排是text1、label1、text2、label2、text3;第二排是text4、label3、text5、label4、text6;第三排是command1,位置在text6的下边。
代码如下:
Private Sub Command1_Click()
Me.Cls
Text1 = Trim(Text1)
Text2 = Trim(Text2)
Text3 = Trim(Text3)
Text4 = Trim(Text4)
Text5 = Trim(Text5)
Text6 = Trim(Text6)
If Text1 = "" Or Text2 = "" Or Text3 = "" Or Text4 = "" Or Text5 = "" Or Text6 = "" Then
MsgBox "至少有一个数值没有输入!" & vbCrLf & " 如果没有该项请填写“0”", vbCritical
Exit Sub
End If
If Not IsNumeric(Text1) Or Not IsNumeric(Text2) Or Not IsNumeric(Text3) Or Not IsNumeric(Text4) Or Not IsNumeric(Text5) Or Not IsNumeric(Text6) Then
MsgBox "至少有一个地方写入了非数值字符!" & vbCrLf & " 不得含有非数值字符。", vbCritical
Exit Sub
End If
Dim a1 As Double, a2 As Double, b1 As Double, b2 As Double, c1 As Double, c2 As Double
a1 = Val(Text1)
b1 = Val(Text2)
c1 = Val(Text3)
a2 = Val(Text4)
b2 = Val(Text5)
c2 = Val(Text6)
c1 = c1 / a1
b1 = b1 / a1
a1 = 1
c2 = c2 / a2
b2 = b2 / a2
a2 = 1
CurrentX = 0
CurrentY = Command1.Top
If b2 = b1 Then
If c1 = c2 Then
Print "因为方程同构,"
Print "该方程组有无穷多对解。"
Else
Print "因为两方程矛盾,"
Print "该方程组无解。"
End If
Exit Sub
End If
y = (c1 - c2) / (b1 - b2)
x = c1 - b1 * y
Print "x="; x
Print "y="; y
End Sub
Private Sub Form_Load()
Text1 = ""
Text2 = ""
Text3 = ""
Text4 = ""
Text5 = ""
Text5 = ""
Text6 = ""
Label1 = "x+"
Label2 = "y="
Label3 = "x+"
Label4 = "y="
Command1.Caption = "求解"
End Sub
我来回复