本文介绍了如何在Matlab中生成遵循偏态正态分布的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有偏态正态分布的概率密度函数,我想在matlab中生成遵循偏态正态分布的随机数.

I have probability density function of skew normal distribution.I want to generate random number that follow the skew normal distribution in matlab.

推荐答案

不能保证其性能/性能,但 http://azzalini.stat.unipd.it/SN/表示以下内容,并具有指向MATLAB函数的.zip文件的链接:

Can't vouch for their performance/adequacy, but http://azzalini.stat.unipd.it/SN/ says the following, and has a link to a .zip file of MATLAB functions:

另请参见此代码基本,但应易于携带.相关摘录如下.它使用RandNorm(也在链接的网页中),它是单位正态分布中的一对数字,在MATLAB中,您应该可以使用randn(2,1).

Also see this code which is in visual Basic, but should be easily portable. Relevant excerpt shown below. This uses RandNorm (also in the linked webpage) which is a pair of numbers from a unit normal distribution, and in MATLAB you should be able to use randn(2,1).

Function RandSkew(fAlpha As Single, _
                  Optional fLocation As Single = 0, _
                  Optional fScale As Single = 1, _
                  Optional bVolatile As Boolean = False) As Single

    ' shg 2008-0919
    ' http://azzalini.stat.unipd.it/SN/faq.html

    ' Returns a random variable with skewed distribution
    '       fAlpha      = skew
    '       fLocation   = location
    '       fScale > 0  = scale

    Dim sigma   As Single
    Dim afRN()  As Single
    Dim u0      As Single
    Dim v       As Single
    Dim u1      As Single

    If bVolatile Then Application.Volatile
    Randomize (Timer)

    sigma = fAlpha / Sqr(1 + fAlpha ^ 2)

    afRN = RandNorm()
    u0 = afRN(1)
    v = afRN(2)
    u1 = sigma * u0 + Sqr(1 - sigma ^ 2) * v

    RandSkew = IIf(u0 >= 0, u1, -u1) * fScale + fLocation
End Function

这篇关于如何在Matlab中生成遵循偏态正态分布的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 14:34