Dim x, y, z As IntegerPrivate Sub Command1_Click() Dim a As IntegerFor y = 1 To 300 For x = 1 To 300 For z = 1 To 300If (y + z) / x > 3.6 And (x + z) / y > 2.02 And (x + y) / z > 2.65 ThenPrint x, y, z GoTo aaa: ElseEnd If Next z Next x Next yaaa: MsgBox x MsgBox y MsgBox z End Sub我编一个程序。但是执行太慢了。 到300就已经要五分钟了。 还有没有其它的办法??
Dim x, y, z As Integer Dim strdic As String Private Sub Command1_Click() Dim i As Integer For x = 1 To 3000 For y = 1 To 3000 For z = 1 To 3000 DoEvents If ((y + z) > (3.6 * x)) Then DoEvents If ((x + z) > (2.02 * y)) Then DoEvents If ((x + y) > (2.65 * z)) Then List1.AddItem "x=" + Str(x) + "y=" + Str(y) + "z=" + Str(z) End If End If End If Next z Next y Next x End SubPrivate Sub Form_Load() Timer1.Interval = 100 End SubPrivate Sub Timer1_Timer() Command1.Caption = "计算中" + strdic strdic = strdic + "." If (Len(strdic) > 5) Then strdic = "." End Sub只要你有时间就等吧
我的程序花了一秒钟就把x,y,z的最大值计算出来了,剩下的应该比较简单 不过我没有验证,基本思路应该没有什么问题,搂主自己验证,另外最小值也自己算算 Dim x, y, z As IntegerPrivate Sub Command1_Click()Dim a As Integer Dim x1 As Double Dim y1 As Double Dim z1 As Double Dim sTime As StringsTime = Time x1 = 10000: y1 = 10000: z1 = 10000 getRange x1, y1, z1, 0.1sTime = sTime & vbTab & Time MsgBox sTime Stop For y = 1 To y1 For x = 1 To x1 For z = 1 To z1 If (y + z) / x > 3.6 And (x + z) / y > 2.02 And (x + y) / z > 2.65 Then Print x, y, z GoTo aaa: End If Next z Next x Next yaaa: MsgBox x MsgBox y MsgBox z End SubPrivate Function getRange(xMax As Double, yMax As Double, zMax As Double, dPrecision As Double) Dim pxMax As Double Dim pyMax As Double Dim pzMax As Double
你的是不定式了,不仅是不等式
有无数解吧 y+z>3.6x
还是不等式组?
(x+y)>2.65z
这个不等式组应该是这样的。
Dim a As IntegerFor y = 1 To 300
For x = 1 To 300
For z = 1 To 300If (y + z) / x > 3.6 And (x + z) / y > 2.02 And (x + y) / z > 2.65 ThenPrint x, y, z
GoTo aaa:
ElseEnd If
Next z
Next x
Next yaaa:
MsgBox x
MsgBox y
MsgBox z
End Sub我编一个程序。但是执行太慢了。
到300就已经要五分钟了。
还有没有其它的办法??
Dim strdic As String
Private Sub Command1_Click()
Dim i As Integer
For x = 1 To 3000
For y = 1 To 3000
For z = 1 To 3000
DoEvents
If ((y + z) > (3.6 * x)) Then
DoEvents
If ((x + z) > (2.02 * y)) Then
DoEvents
If ((x + y) > (2.65 * z)) Then
List1.AddItem "x=" + Str(x) + "y=" + Str(y) + "z=" + Str(z)
End If
End If
End If
Next z
Next y
Next x
End SubPrivate Sub Form_Load()
Timer1.Interval = 100
End SubPrivate Sub Timer1_Timer()
Command1.Caption = "计算中" + strdic
strdic = strdic + "."
If (Len(strdic) > 5) Then strdic = "."
End Sub只要你有时间就等吧
不过我没有验证,基本思路应该没有什么问题,搂主自己验证,另外最小值也自己算算
Dim x, y, z As IntegerPrivate Sub Command1_Click()Dim a As Integer
Dim x1 As Double
Dim y1 As Double
Dim z1 As Double
Dim sTime As StringsTime = Time
x1 = 10000: y1 = 10000: z1 = 10000
getRange x1, y1, z1, 0.1sTime = sTime & vbTab & Time
MsgBox sTime
Stop
For y = 1 To y1
For x = 1 To x1
For z = 1 To z1
If (y + z) / x > 3.6 And (x + z) / y > 2.02 And (x + y) / z > 2.65 Then
Print x, y, z
GoTo aaa:
End If
Next z
Next x
Next yaaa:
MsgBox x
MsgBox y
MsgBox z
End SubPrivate Function getRange(xMax As Double, yMax As Double, zMax As Double, dPrecision As Double)
Dim pxMax As Double
Dim pyMax As Double
Dim pzMax As Double
'根据(y + z) / x > 3.6计算x的最大值
pxMax = (yMax + zMax) / 3.6
'根据(x + z) / y > 2.02计算y的最大值
pyMax = (pxMax + zMax) / 2.02
'根据(x + y) / z > 2.65计算y的最大值
pzMax = (pxMax + pyMax) / 2.65
DoEvents
'检查精度是否已经满足要求
If Abs(pxMax - xMax) <= dPrecision And Abs(pyMax - yMax) <= dPrecision And Abs(pzMax - zMax) <= dPrecision Then
xMax = pzMax
yMax = pyMax
zMax = pzMax
Else
'再进一步计算更精确的值
xMax = pzMax
yMax = pyMax
zMax = pzMax
DoEvents
getRange xMax, yMax, zMax, dPrecision
End If
End Function
那不就是无解吗?
=====================
哦,如果加上这个条件就是了。