English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

寫一個程式,輸入X的值,並計算e^x

e^x = 1+X+(x^2) / 2! +(X^3) / 3! +........+(X^n) / n!

(計算至 【(X^n) / n! 】 <10^(-5) ) 
     ↑粗框地方要絕對值
      
      

2007-02-04 07:58:18 · 2 個解答 · 發問者 Anonymous in 電腦與網際網路 程式設計

2 個解答

這是 ex 函數的副程式
你祇要呼叫及傳入 x 值即可
例如 在主程式裡
Print Taylor(1)
就會印出 e 值
Public Function Taylor(x As Single) As Single
Dim d, y As Single
Dim n As Double
Dim i As Integer
i = 0
n = 1
y = 1
Taylor = 1
Do
i = i + 1
n = n * i ' 計算 n!
y = y * x ' 計算 xn
d = y / n ' 計算 xn/n!
Taylor = Taylor + d
Loop Until Abs(d) < 0.00001
End Function
如果有問題, 請來函討論. 不然, 我可能會錯失你再補充的疑點.

2007-02-07 03:33:50 · answer #1 · answered by JJ 7 · 0 0

我幫你寫了一個範例~~
妳去下載來看看吧~~
http://w1.loxa.com.tw/ahong/knowledge/kn002.zip

====================================================


x = Val(Text1)
i = 0
y = 1

Do
k = 1
i = i + 1
For j = 1 To i
k = k * j
Next j
p = (x ^ i) / k
y = y + p
Loop While p > 10 ^ (-5) Or p < (-1) * 10 ^ (-5)

Label3 = y

2007-02-06 10:34:33 · answer #2 · answered by 邁向知識達人 3 · 0 0

fedest.com, questions and answers