|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Function GetV(dbTarget As Double) As Double
Dim dbL,dbH,dbM,dbV,dbP,dbSkip As Double
Dim blSkip As Boolean
dbL = 0 'x的下界
dbH = 10000000 'x的上界
dbP = 0.0001 '与目标值的误差
dbSkip = 0.000001 '没有结果的判定(当下界与上界的差小于等于此值时,认为在给定范围内无解——此程序用-1表示无解)
dbM = (dbH - dbL) / 2 '中点值
dbV = dbM * Log(dbM / 30) '代数式
Do Until Abs(dbV - dbTarget) <= dbP
If dbH - dbL <= dbSkip Then '下界与上界是否接近临界值
blSkip = True '跳出,无解
Exit Do
End If
If dbV > dbTarget Then
dbH = dbM
Else
dbL = dbM
End If
dbM = dbL + (dbH - dbL) / 2
dbV = dbM * Log(dbM / 30)
' Debug.Print dbL, dbH, dbM, dbV, dbTarget
Loop
GetV = IIf(blSkip, -1, dbM) '根据blskip判断是否是无解跳出
End Function
Sub test ()
Dim i As Long
For i = 2 To [a1].End(xlDown).Row
Cells(i, 2) = GetV(Cells(i, 1))
Next
End Sub |
|