作者mycircle (mycircle)
看板Visual_Basic
标题[.NET] 如何在.NET写出查常态分配机率的Z值表
时间Mon Apr 2 05:04:15 2007
我在奇摩知识上看到的
http://0rz.tw/832xF
一位大大写的我把他转述出来 但是和EXCEL的内建函数NORMSDIST机率正确值
还是有一段差距 我的问题是有没有大大能够帮我改改程式码使他的值能够更精准
的逼近正确值 因为我一定要使用内建的程式码来跑出机率值来(不可以使用EXCEL)
谢谢!!
Const myStart As Double = -3.5
Const myLength As Double = 0.0001
Dim x As Double, myEnd As Double, myProb As Double
Dim myStep As Double, i As Double
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
countCDF()
End Sub
Sub countCDF()
Do
myProb = 0
myEnd = InputBox("CDF of Standard Normal Dist. x", "输入 X 的值")
If myEnd = 0 Then
MsgBox("Standrad Normal CDF = 0.5")
Exit Sub
ElseIf myEnd >= Math.Abs(myStart) Then
MsgBox("Standrad Normal CDF = 1")
Exit Sub
ElseIf myEnd <= myStart Then
MsgBox("Standrad Normal CDF = 0")
Exit Sub
Else
myStep = (myEnd - myStart) / myLength
x = myStart
For i = 1 To myStep
myProb = myProb + (myLength * (1 / Math.Sqrt(2 *
3.14159265358979)) * Math.Exp(-(x ^ 2 / 2)))
x = x + myLength
Next i
End If
MsgBox("Standrad Normal CDF = " & myProb)
Loop
End Sub
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.223.0.50