Calculating expectation for a custom distribution in Mathematica

后端 未结 3 1739
后悔当初
后悔当初 2021-01-19 21:18

This question builds on the great answers I got on an earlier question:

Can one extend the functionality of PDF, CDF, FindDistributionParameters etc in Mathematica?<

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-19 22:05

    I'm not sure I really understand your question... The expected value or the mean, is the first moment of the distribution and can be calculated as

    expectation := Integrate[x #, {x,-Infinity,Infinity}]&;
    

    and use it as expectation[f[x]], where f[x] is your pdf.

    Your last code snippet doesn't work for me. I don't know if it is v8 code or if it is custom defined or if you're trying to say that is what you'd like your function to be like...

    You can also try looking into Mathematica's ExpectedValue function.

    ExpectedValue[x, NormalDistribution[m, s], x]
    Out[1] = m
    

提交回复
热议问题