Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Integration
Date: Wed, 22 Feb 2012 04:15:12 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 16
Message-ID: <ji1q4g$on4$1@newscl01ah.mathworks.com>
References: <ji1bhj$cvt$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1329884112 25316 172.30.248.45 (22 Feb 2012 04:15:12 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 22 Feb 2012 04:15:12 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:758456

"steingre" wrote in message <ji1bhj$cvt$1@newscl01ah.mathworks.com>...
> lambda(1)=1/8;
> Num=10000;
> for i=1:Num
>       y(i,1) = i*10/Num;
>       z(i,1) = exppdf(y(i,1),(1./lambda(1,1)));
> end
> trapz(y,z)
> 
> Why do I not get 1?
- - - - - - - - -
  You haven't gone far enough out in the range of y to approximate infinity.  You have stopped where y is equal to 10 which makes exppdf equal to 1/8*exp(-10/8) = .0358 .  This is not nearly far enough.  Also you started at y = 0.001 instead of zero, another source of error.  Finally, you should not expect exact answers because trapezoidal integration is only a numerical approximation to the ideal integral value.

  By the way, you *are* using uniform spacing here.  Each interval in y is 0.001 .

Roger Stafford