"bob bobby" wrote in message <ifhsdp$fj$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <ifhra6$icu$1@fred.mathworks.com>...
> > "bob bobby" wrote in message <ifgl7c$pf2$1@fred.mathworks.com>...
> > > Hi all!
> > > I'm a new Matlab user and I'm loving the software and this newsgroup! I'm having an issue using the quad function to numerically integrate the following and I can't find any solution that is applicable to it on the newsgroup or on google! Any help is much appreciated!
> > >
> > > basically have 2 normally distributed random variables s and x, whose pdfs are f and g and cdfs are F and G.
> > >
> > > the function i need to solve is the following: (click link for image in clean mathematical format)
> > > http://www.sitmo.com/gg/latex/latex2png.2.php?z=100&eq=\int_{100}^{100}(\int_{B*s}^{1(B*s)}%20F(x)%20%20dx)%20g(s)ds
> > >
> > > f = @(x) normcdf(x);
> > > b = 0.2;
> > > f2 = @(s) quad(f,(b*s),1(b*s));
> > > g= @(y) normpdf(y)*f2(y);
> > > quad(g, 100, 100)
> > >
> > > I thought I was being smart using the above but I get the following errors:
> > >
> > > ??? Error using ==> quad at 70
> > > The limits of integration must be scalars.
> > >
> > > Error in ==> @(s)quad(f,(b*s),1(b*s))
> > >
> > > Error in ==> @(y)normpdf(y)*f2(y)
> > >
> > > Error in ==> quad at 77
> > > y = f(x, varargin{:});
> > >
> > > Error in ==> file at 6
> > > quad(g, 100, 100)
> > >
> > >
> > > Thanks for any help you can give me
> > > Cheers
> > > Rob
> >
> > (By the way, this is a bit of a quiet time of the year, so
> > don't be so impatient.)
> >
> > READ THE ERROR MESSAGE!
> >
> > Your inner integral has the parameter s in the limits of
> > integration.
> >
> > What does the error message say? Read it again. Here, I
> > will repeat it for you.
> >
> > > ??? Error using ==> quad at 70
> > > The limits of integration must be scalars.
> >
> > When quad runs, it does not pass in single points to
> > evaluate the function at. It can often pass in several
> > points for efficiency. So what happens inside the
> > internal integral when it gets several values for s? Yes.
> > it tries to call quad with a list of limits of integration,
> > so quad kicks out with an error.
> >
> > Obviously, you can fix this by putting the internal call
> > to quad in a loop.
> >
> > Read the error messages. They are put there for a
> > reason.
> >
> > John
>
> I think I have come up with an alternative solution:
>
> quad2d(@(x,s) normpdf(s).*normcdf(x),100, 100, @(s) s*b, @(s) 1(b*s))
Yes, it should work, as quad2d does accept problems
where the limits of integration are a function of the
outer variable.
But test it yourself. Verify that the result makes sense.
John
