111
This commit is contained in:
12
120-3.py
12
120-3.py
@@ -1,11 +1,11 @@
|
||||
x1, x2 = 3, 6
|
||||
|
||||
x1, x2 = 3, 6
|
||||
|
||||
def fx(x):
|
||||
return x/(4+x**2)
|
||||
|
||||
# 复合Newton-Cotes公式 复合牛顿-科特斯公式
|
||||
# n等分参数,x1到x2的区间,type=1表示梯形法,type=2表示辛普森法
|
||||
# 复合Newton-Cotes公式 复合牛顿-柯特斯公式
|
||||
# n等分参数,x1到x2的区间,type=1表示梯形法,type=2表示辛普生法
|
||||
def CompositeNewtonCotes(n, type):
|
||||
if type == 1:
|
||||
h = (x2 - x1) / n
|
||||
@@ -25,8 +25,8 @@ def CompositeNewtonCotes(n, type):
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 复合梯形公式,点数为n+1
|
||||
print("复合梯形公式\n", CompositeNewtonCotes(8, 1))
|
||||
# 复合辛普森公式,点数为2n+1
|
||||
print("复合辛普森公式\n", CompositeNewtonCotes(4, 2))
|
||||
print("复合梯形公式\n", CompositeNewtonCotes(8, 1)) #8等分,1代表是梯形公式
|
||||
# 复合辛普生公式,点数为2n+1
|
||||
print("复合辛普生公式\n", CompositeNewtonCotes(4, 2)) #4等分,2代表是辛普生公式
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user