分割10000段由0到pi做積分依然有極小的誤差
vb
Function func(ByVal a As Single) As Single
func = (1 + 2 ^ a) * Sin(a)
End Function
Private Sub Command1_Click()
a = Val(InputBox("下限a="))
b = Val(InputBox("上限b="))
n = Val(InputBox("分割n=", "等分"))
pi = 3.1415926535
a1 = a
a2 = a
dx = (b - a) / n
For i = 1 To n
a1 = a2
a2 = a1 + dx
Y1 = func(a1)
Y2 = func(a2)
subsol = (Y1 + Y2) * dx / 2
sol = sol + subsol
Next i
sol = sol - (2 + ((2 ^ pi) + 1) / (1 + (Log(2)) ^ 2))
MsgBox sol