用VB求二元一次方程的解
a1*x+b1*y+c1=0
a2*x+b2*y+c2=0
只需将下面代码复制到窗体中测试即可
private
sub
form_load()
dim
a1
as
single
dim
b2
as
single
dim
a2
as
single
dim
b1
as
single
dim
c1
as
single
dim
c2
as
single
dim
rootx
as
single
dim
rooty
as
single
a1
=
inputbox("请输入第一个方程的x的系数:")
b1
=
inputbox("请输入第一个方程的y的系数:")
c1
=
inputbox("请输入第一个方程的常数项:")
c1
=
-c1
a2
=
inputbox("请输入第二个方程的x的系数:")
b2
=
inputbox("请输入第二个方程的y的系数:")
c2
=
inputbox("请输入第二个方程的常数项:")
c2
=
-c2
rooty
=
(a1
*
c2
-
a2
*
c1)
/
(a1
*
b2
-
a2
*
b1)
rootx
=
(c1
-
b1
*
rooty)
/
a1
msgbox
"原方程组的解为:"
&
vbcrlf
&
"x="
&
rootx
&
vbcrlf
&
"y="
&
rooty
&
vbcrlf
end
sub
2024-10-13 广告
编程的话,就用公式法y=f(x),y是x的关于abc函数,
x任意赋值得y。。。没意义啊,
3000x+270y=593623求xy可能的值
若题目是ax+by=c
dx+ey=f
退化情况就是a=kd,b=ke,c=kf只有一个方程,分三种情况求x和y
L=a*e-b*d
select case L
case 0
if a*f-c*d=0 then
msgbox "方程有无数解!!"
else
msgbox "方程无解!!!!"
end if
case else
x=(c*e-b*f)/L
y=(a*f-c*d)/L
end select
语句是参见同类问题一的回答,引用
界面布局
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
Dim d As Single, x1 As Single, x2 As Single
a = Text1
b = Text2
c = Text3
d = b * b - 4 * a * c
If d >= 0 Then
x1 = (-b + Sqr(d)) / (2 * a)
x2 = (-b - Sqr(d)) / (2 * a)
Text4 = Format(x1, "0.##")
Text5 = Format(x2, "0.##")
Else
MsgBox "在实数范围内无解"
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Command1.Caption = "计算"
Command2.Caption = "结束"
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Command1.Caption = "计算"
Command2.Caption = "结束"
End Sub
能否把它发到我的邮箱44788451@qq.com
还发什么,你按照我的界面布局的图片自己添加5个文本框控件和两个按钮控件,然后把代码copy过去就完事了。
广告 您可能关注的内容 |