2018年12月31日 星期一

範例EX4-2 利用梯行法計算(exp(-pow(x,2)/2)) / sqrt(2*3.14159) , x=-5.3 to 3.0 的積分值---python語言

範例EX4-2 利用梯行法計算(exp(-pow(x,2)/2)) / sqrt(2*3.14159) , x=-5.3 to 3.0 的積分值---python語言



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

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: H:/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...