2019年1月21日 星期一

例題4-3 計算 exp( - (z^2)/2 ) / (2* Pi ) 在[-5.0, +5.0]的定積分


例題4-3 計算 exp( -  (z^2)/2 ) /  (2* Pi )  在[-5.0,  +5.0]的定積分

n=100 , a=-5  , b=+5


# 利用梯行積分法求方程式近似解

from math import *

def F(x):
    temp=(1.0 /exp(x*x/2))
    return temp

n=100
a=-5.0
b=5.0
sum1=0.0
h=(b-a)/n
x=a
for i in range (1,n):
    x=x+h
    sum1=sum1+F(abs(x))
    tn=(1.0/sqrt(2*pi))*(h/2.0)*(F(fabs(a))+F(fabs(b))+2.0*sum1)

print("T{%d}={%10.6f}\n" %(n,tn))


輸出畫面
========= RESTART: F:\2018-09勤益科大數值分析\數值分析\PYTHON\EX4-3.py =============
T{100}={  0.999999}

沒有留言:

張貼留言

Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3

  Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3 AngularJS 實例 <!DOCTYPE html> <html> <head> <meta charse...