用Excel计算积分?如何进行?
2个回答
展开全部
1 Public Function 梯形积分(r As String, a As Double, b As Double, n As Integer) As Double
2 Dim dx As Double, i As Integer
3 dx = (b - a) / n
4 For i = 1 To n
5 梯形积分 = 梯形积分 + fx(r, (a + dx * (i - 1 / 2))) * dx
6 Next i
7 End Function
8 Public Function 复化辛普生积分(r As String, a As Double, b As Double, n As Integer) As Double
9 Dim dx As Double, i As Integer, m As Integer
10 m = 2 * n
11 dx = (b - a) / m
12 复化辛普生积分 = fx(r, a) + fx(r, b)
13 For i = 2 To m Step 2
14 复化辛普生积分 = 复化辛普生积分 + 4 * fx(r, (a + dx * (i - 1))) + 2 * fx(r, (a + dx * i))
15 Next i
16 复化辛普生积分 = (复化辛普生积分 - 2 * fx(r, (a + dx * m))) * dx / 3
17 End Function
18 Public Function fx(f As String, x As Double) As Double
19 f = LCase(f)
20 fx = Evaluate(Replace(f, "x", x))
21 End Function
两个函数的参数都是1.积分函数,自变量用x表示,x不区分大小写2.积分下限3.积分上限4.划分次数,不能大于32766,对于梯形积分,越大越接近真值,对于复化辛普生积分,没必要使用大的划分次数积分区间包含奇点(趋近于无穷的点),复化辛普生公式将不能正确积分,将来可能会修正也希望高手出招调用方法:=梯形积分("sin(x)^3-ln(x+1)^3+x^5-x", 0, 2, 2000)
2 Dim dx As Double, i As Integer
3 dx = (b - a) / n
4 For i = 1 To n
5 梯形积分 = 梯形积分 + fx(r, (a + dx * (i - 1 / 2))) * dx
6 Next i
7 End Function
8 Public Function 复化辛普生积分(r As String, a As Double, b As Double, n As Integer) As Double
9 Dim dx As Double, i As Integer, m As Integer
10 m = 2 * n
11 dx = (b - a) / m
12 复化辛普生积分 = fx(r, a) + fx(r, b)
13 For i = 2 To m Step 2
14 复化辛普生积分 = 复化辛普生积分 + 4 * fx(r, (a + dx * (i - 1))) + 2 * fx(r, (a + dx * i))
15 Next i
16 复化辛普生积分 = (复化辛普生积分 - 2 * fx(r, (a + dx * m))) * dx / 3
17 End Function
18 Public Function fx(f As String, x As Double) As Double
19 f = LCase(f)
20 fx = Evaluate(Replace(f, "x", x))
21 End Function
两个函数的参数都是1.积分函数,自变量用x表示,x不区分大小写2.积分下限3.积分上限4.划分次数,不能大于32766,对于梯形积分,越大越接近真值,对于复化辛普生积分,没必要使用大的划分次数积分区间包含奇点(趋近于无穷的点),复化辛普生公式将不能正确积分,将来可能会修正也希望高手出招调用方法:=梯形积分("sin(x)^3-ln(x+1)^3+x^5-x", 0, 2, 2000)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询