fix
This commit is contained in:
10
120-3.py
10
120-3.py
@@ -4,7 +4,7 @@ x1, x2 = 3, 6
|
||||
def fx(x):
|
||||
return x/(4+x**2)
|
||||
|
||||
# n等分,x1到x2的区间,type=1表示梯形法,type=2表示辛普森法
|
||||
# n等分参数,x1到x2的区间,type=1表示梯形法,type=2表示辛普森法
|
||||
def CompositeNewtonCotes(n, type):
|
||||
if type == 1:
|
||||
h = (x2 - x1) / n
|
||||
@@ -23,5 +23,9 @@ def CompositeNewtonCotes(n, type):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Composite Trapezoidal Rule: ", CompositeNewtonCotes(8, 1))
|
||||
print("Composite Simpson's Rule: ", CompositeNewtonCotes(4, 2))
|
||||
# 复合梯形公式,点数为n+1
|
||||
print("复合梯形公式\n", CompositeNewtonCotes(8, 1))
|
||||
# 复合辛普森公式,点数为2n+1
|
||||
print("复合辛普森公式\n", CompositeNewtonCotes(4, 2))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user