开发者

Trapz gives negative result: why?

开发者 https://www.devze.com 2023-03-26 02:51 出处:网络
I a开发者_开发技巧m trying to numerically integrate a Generalized Normal Distribution. I expect the area under it to be 1. What I get is -1. Why is it like this?

I a开发者_开发技巧m trying to numerically integrate a Generalized Normal Distribution. I expect the area under it to be 1. What I get is -1. Why is it like this?

mu=0;
alpha=0.5;
beta=2;

x=-2:0.01:2;
densityGG = beta/(2*alpha*gamma(1/beta)) * exp(-power(abs(x-mu)/alpha,beta));

plot(x,densityGG);
trapz(densityGG,x)


The function is actually

trapz(X, Y)

So try

trapz(x, densityGG)

and it should sort things out.


read the help file of Trapz... it's all there

you need to write: trapz(x,densityGG)

0

精彩评论

暂无评论...
验证码 换一张
取 消