VB编写公式
答案:1 悬赏:0 手机版
解决时间 2021-02-09 02:13
- 提问者网友:龅牙恐龙妹
- 2021-02-08 11:14
VB编写公式
最佳答案
- 五星知识达人网友:夜余生
- 2021-02-08 11:22
Private Sub Command1_Click()
Dim s() As Double, n() As Double
Dim A As Double, B As Double
Dim i As Integer, n1 As Integer
On Error GoTo er
n1 = 5
For i = 0 To n1 - 1
ReDim Preserve s(i)
s(i) = CDbl(InputBox("请输入S(" & i + 1 & ")"))
Next
For i = 0 To n1 - 1
ReDim Preserve n(i)
n(i) = CDbl(InputBox("请输入N(" & i + 1 & ")"))
Next
B = (Sum_S_N_log(s(), n()) - (Sum_log(s()) * Sum_log(n())) / n1) / (Sum_log2(s()) - Sum_log(s()) ^ 2 / n1)
A = Sum_log(n()) / n1 - Sum_log(s()) * B / n1
MsgBox "B=" & Format(B, "0.00000") & " A=" & Format(A, "0.00000")
er:
End Sub
Private Function Sum_log(s() As Double) As Double
Dim i As Integer, s1 As Double
For i = LBound(s) To UBound(s)
s1 = s1 + Log(s(i)) / Log(10)
Next
Sum_log = s1
End Function
Private Function Sum_log2(s() As Double) As Double
Dim i As Integer, s1 As Double
For i = LBound(s) To UBound(s)
s1 = s1 + (Log(s(i)) / Log(10)) ^ 2
Next
Sum_log2 = s1
End Function
Private Function Sum_S_N_log(s() As Double, n() As Double) As Double
Dim i As Integer, s1 As Double
For i = LBound(s) To UBound(s)
s1 = s1 + Log(s(i)) * Log(n(i)) / Log(10) ^ 2
Next
Sum_S_N_log = s1
End Function
Dim s() As Double, n() As Double
Dim A As Double, B As Double
Dim i As Integer, n1 As Integer
On Error GoTo er
n1 = 5
For i = 0 To n1 - 1
ReDim Preserve s(i)
s(i) = CDbl(InputBox("请输入S(" & i + 1 & ")"))
Next
For i = 0 To n1 - 1
ReDim Preserve n(i)
n(i) = CDbl(InputBox("请输入N(" & i + 1 & ")"))
Next
B = (Sum_S_N_log(s(), n()) - (Sum_log(s()) * Sum_log(n())) / n1) / (Sum_log2(s()) - Sum_log(s()) ^ 2 / n1)
A = Sum_log(n()) / n1 - Sum_log(s()) * B / n1
MsgBox "B=" & Format(B, "0.00000") & " A=" & Format(A, "0.00000")
er:
End Sub
Private Function Sum_log(s() As Double) As Double
Dim i As Integer, s1 As Double
For i = LBound(s) To UBound(s)
s1 = s1 + Log(s(i)) / Log(10)
Next
Sum_log = s1
End Function
Private Function Sum_log2(s() As Double) As Double
Dim i As Integer, s1 As Double
For i = LBound(s) To UBound(s)
s1 = s1 + (Log(s(i)) / Log(10)) ^ 2
Next
Sum_log2 = s1
End Function
Private Function Sum_S_N_log(s() As Double, n() As Double) As Double
Dim i As Integer, s1 As Double
For i = LBound(s) To UBound(s)
s1 = s1 + Log(s(i)) * Log(n(i)) / Log(10) ^ 2
Next
Sum_S_N_log = s1
End Function
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯