请教各位大神,在VB中如何计算余误差函数(erfc)
请教各位大神,在VB中如何计算余误差函数(erfc),在工作中经常用到该函数来计算数值!想在VB中实现程序化计算,这样工作效率会提高很多!查找很多资料都没有找到!请各位大神指点!
程序代码:
Public Function 复化辛普生积分(a As Double, b As Double, n As Integer) As Double 'a、b为积分上下限, n为积分区间划分份数 Dim dx As Double, i As Integer, m As Integer m = 2 * n dx = (b - a) / m 复化辛普生积分 = f(a) + f(b) For i = 2 To m Step 2 复化辛普生积分 = 复化辛普生积分 + 4 * f((a + dx * (i - 1))) + 2 * f((a + dx * i)) Next i 复化辛普生积分 = (复化辛普生积分 - 2 * f((a + dx * m))) * dx / 3 End Function Function Integration( a As Double, b As Double) '矩形方法,a、b为积分上下限,次数由精度控制 Dim h As Double, x As Double n = 2 s = 0 p = f(a) + f(b) Do h = (b - a) / n / 2 s2 = 0 x = a + h s4 = f(x) For i = 2 To 2 * n - 1 Step 2 x = x + h s2 = s2 + f(x) x = x + h s4 = s4 + f(x) Next i s = h / 3 * (p + 2 * s2 + 4 * s4) If (Abs(s - s0)) / Abs(s) <= 0.000001 Then Exit Do '误差精度 s0 = s n = 2 * n Loop Integration = s End Function Function f(x as double) as double f= 1/x ' 积分符号内部的表达式, 这里是f(x)=1/x End Function
[此贴子已经被作者于2017-10-9 09:13编辑过]