机械优化设计一维搜索vb编程

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

单峰区间确定

Fun ctio n f(x As Si ngle) As Double

f = Val(Text3.Text) * x * x + Val(Text4.Text) * x + Val(Text5.Text) End Function

Private Sub Comma nd1_Click()

Dim a!, b!, aO!, h!

Dim a1!, a2!, a3!

Dim f1!, f2!, f3!

a0 = Val(Text1.Text)

h = Val(Text2.Text)

a1 = a0

f1 = f(a1)

a2 = a1 + h

f2 = f(a2)

If f2 >= f1 The n

h = -h

a3 = a1: f3 = f1

a1 = a2: f1 = f2

a2 = a3: f2 = f3

a3 = a2 + h

f3 = f(a3)

Else

a3 = a2 + h

f3 = f(a3)

End If

Do

h = 2 * h: a1 = a2

f1 = f2: a2 = a3

f2 = f3: a3 = a2 + h

f3 = f(a3)

Loop While f3 < f2

If a1 < a3 The n

a = a1

b = a3

Else

a = a3

b = a1

End If

Label4.Caption = "o??很a="&a &Space(5) & ”?6他?"&b

End Sub

Private Sub Comma nd2_Click()

End

End Sub

黄金分割法

Fun ctio n f(x As Si ngle) As Double

f = Val(Textl.Text) * x A 2 + Val(Text6.Text) * x + Val(Text5.Text)

End Function

Private Sub Comma nd1_Click()

Dim a!, b!, e!, a3!

Dim a1!, a2!, f1!, f2!, F3!

a = Val(Text2):

b = Val(Text3): e = Val(Text4)

al = b - 0.618 * (b - a): a2 = a + 0.618 * (b - a)

fl = f(a1)

f2 = f(a2)

Do

If fl >= f2 Then

a = a1: al = a2: fl = f2

a2 = a + 0.618 * (b - a)

f2 = f(a2)

Else

b = a2: a2 = a1: f2 = fl

al = b - 0.618 * (b - a)

fl = f(a1)

End If

Loop Un til b - a <= e

a3 = (a + b) / 2

F3 = f(a3)

Label1.Caption ="求优结果:” &Chr(13) + Chr(10) & ” 函数在 x="&a3 &Chr(13) + Chr(10) & ” 极值为:” &Format(F3, "0.00000")

End Sub

Private Sub Comma nd2_Click()

End End Sub

相关文档
最新文档