Danilo
Danilo

Reputation: 2686

Trapz gives negative result: why?

I am 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)

Upvotes: 1

Views: 5095

Answers (2)

Rasman
Rasman

Reputation: 5359

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

you need to write: trapz(x,densityGG)

Upvotes: 2

Gustav Larsson
Gustav Larsson

Reputation: 8497

The function is actually

trapz(X, Y)

So try

trapz(x, densityGG)

and it should sort things out.

Upvotes: 4

Related Questions