作者ruby791104 (阿年:))
看板Visual_Basic
標題[.NET] VB 2008 計算Exponential Function的程式寫法
時間Mon Nov 2 12:51:31 2009
我要寫一個可以計算exponential function的程式,
exponential公式是:e^x = 1 + x + x^2/2! + x^3/3! + x^4/4! + …
以下是我寫的程式,
我知道錯誤的地方應該蠻多的,
但是我不知道從何改起@@,
拜託各位大大幫幫忙!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, number_of_terms, i, n As Integer
Dim result, factorial As Double
x = TextBox1.Text
number_of_terms = TextBox2.Text
n = number_of_terms
If RadioButton1.Checked Then
factorial = 1
For i = 1 To n
factorial = factorial * i
Next
result = x ^ (n - 1) / factorial
Label4.Text = result
End If
End Sub
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.240.186.200
推 Marty:有內建函式Math.exp()可以用唷..你要不要試試看?? 11/02 13:09
→ MOONRAKER:這應該是一種作業或練習吧,才要寫逼近法 11/02 15:18
→ MOONRAKER:你現在只有寫一項,再用個for讓他自己算到n項就得了 11/02 15:18
→ MOONRAKER:記得每次算出來結果要累加起來 11/02 15:19
→ ruby791104:TO:MOONRAKER大大 11/02 21:09
→ ruby791104:真的很謝謝你唷,讓我開竅了! 11/02 21:10
→ ruby791104:自己寫出來的感覺真好XD 11/02 21:18
→ MOONRAKER:有寫出來就好… 11/02 23:37
→ MOONRAKER:也可以10^4-10^7次迭代算出的值和內建exp()比較精確度 11/02 23:41