How to get the mean of a function when the input of the function is a distribution?

2 ビュー (過去 30 日間)
Jen W
Jen W 2018 年 1 月 15 日
回答済み: Torsten 2018 年 1 月 15 日
I want to get the expectation of y=sin(x) when x follows a distribution described below. But the second line has error. How can I fix this?
x=makedist('Uniform','Lower',0,'Upper',pi/2)
y=sin(x);
mean(y)

採用された回答

Walter Roberson
Walter Roberson 2018 年 1 月 15 日
編集済み: Walter Roberson 2018 年 1 月 15 日
The easiest approach is the numeric one:
>> mean(sin(random(x,1,10000)))
ans =
0.636616269663442
>> mean(sin(random(x,1,10000)))
ans =
0.636757666186139
>> mean(sin(random(x,1,10000)))
ans =
0.632276664694085
If you need the theoretical answer then rely upon the fact that you have a uniform distribution and calculate the expectation of sin(x) x from 0 to pi/2 symbolically:
syms x
int(sin(x),x,0,pi/2)/(pi/2)
Numerically this comes out as about 0.636619772367581

その他の回答 (1 件)

Torsten
Torsten 2018 年 1 月 15 日
I think you will have to go back to the general definition of the mean of a probability distribution.
Best wishes
Torsten.

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by