例題4-2 計算 exp( - (z^2)/2 ) / (2* Pi ) 在[-3.5, -3.0]的定積分
'''
import math
def f(x) :
return (math.exp( -0.5*x*x) ) / pow( ( 2* math.pi) , 0.5)
def computeT(a , b , n) :
h = (b - a) / n
T = 0.0
for i in range (1 , n ):
T += f(a + i * h) # //1 <= k <= n - 1
return (h * 0.5 * ( f(a) + 2 * T + f(b) ) )
n = 10 #//區間等分數
a = -3.5
b = -3.0 #//上下限
print("answer = {%10.6f}\n" %( computeT(a, b, n) ) )
輸出畫面
======= RESTART: F:\2018-09勤益科大數值分析\數值分析\PYTHON\EX4-2-0.py ==========
answer = { 0.001119}
>>>
https://www.wolframalpha.com/input/?i=integrate++exp(+-+(x%5E2)%2F2+)+++%2F++(2*+Pi+)+%5E0.5
integrate exp( - (x^2)/2 ) / (2* Pi ) ^0.5
沒有留言:
張貼留言