From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Double integration
Date: Wed, 27 Apr 2011 21:17:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 21
Message-ID: <ipa14h$quv$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1303939025 27615 (27 Apr 2011 21:17:05 GMT)
NNTP-Posting-Date: Wed, 27 Apr 2011 21:17:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2669560
Xref: comp.soft-sys.matlab:724155

hi all!
I've been struggling to figure out how to calculate this double integral using matlab for the last few days and I'm totally stuck. I've read a wide variety of posts about double integrations and quad2d and dblquad but I'm no closer to figuring this out. I'm trying to integrate the following equation (safe link on imageshack):

where s and x are random variables and f(x) and g(s) are the respective pdfs.

I have tried to use the following 
quad2d(@(x,s) normpdf(s).*normpdf(x).*(s+x-1), @(s) 1-s, 500, -500, 500);

but I get this error message:
??? Error using ==> quad2d at 97
A must be a finite, scalar, floating point constant.

which makes sense sure, and I tried switching round the s and the x the limits but I am getting weird results and I am pretty certain it's totally wrong to do this.

I think I need to use a loop to compute the 1-s prior to the integration but I am totally lost. 
I would really appreciate some help here, many thanks.