"Carla Soares" <carla.soares@gmail.com> wrote in message <i0t2cj$m4p$1@fred.mathworks.com>...
> Thanks for your reply! I'm sorry, but I don't get it completly... I now have:
>
> for x=A:RA;
> int1 = @(y,z) (alpha*(cdf(max(0,max(0,max(0,Rmax(0,A+x))max(0,A+x+y))max(0,A+x+y+z))))).*pdf(z).*pdf(x).*pdf(y);
> ymin = 1e5;
> ymax = max(0,Rmax(0,A+x));
> zmax = @(y) max(0,max(0,Rmax(A+x))max(0,A+x+y));
> int2 = quad2d(int1,ymin,ymax,ymin,zmax);
> end
>
> int1 is my original integrand with the 3 variables. A and R are changing values in another loop and cdf and pdf are functions handles for the cdf and pdf of the normal.
> But this gives me a value (and I guess only for the last assumed value of x), I don't see how I get to integrate over x...
> Sorry if this is very basic, but I'm not managing to figure it out...
       
What I had in mind is a function, call it F(X) (or whatever you like,) which can accept a vector X of x values. Within this function there should be a forloop that selects each value xi out of the vector X oneatatime. The number of trips through the forloop is entirely determined by the length of vector X sent to the function each time it is called. Also needed is a subfunction within it which uses this scalar xi as a parameter along with the matrices, Y and Z, which will be the arguments passed to it by quad2d, in order to evaluate the desired integrand for xi and each pair of y,z values in Y and Z. In addition there should be two other subfunctions which use xi as a parameter and evaluate the upper limits of z using matrix Y as an argument and the upper limit of y using only parameter xi. At each pass through the forloop the quad2d function is called on with those
integrand and limit functions as function handles. The result of each call should be the scalar double integral of the integrand over the cross section at the particular x value xi. This result should be placed in a vector, FF, and when the forloop is finished, the vector FF(X) is passed back as an output. (Note that this forloop has nothing to do with variations in your parameters R and A.)
Then outside the above function, the function quad, quadl, or quadgk, whichever you choose, should call on the F function as it integrates from c to d. Note that these three quadrature functions each pass vectors to their integrand functions rather than make calls with single scalar values, which is the reason that F has to be able to receive vectors.
In the code you showed me, there is no evidence of the forloop I have described here. Your forloop appears to be varying x in a fixed way as given by A:RA and not as a vector which has been passed to it from quad (or quadl or quadgk.) There ought to be a piece of code that looks in outline roughly like this:
function FF = F(X)
FF = zeros(size(X)); % Allocate space for FF
for k = 1:length(X)
xi = X(k);
% Then use xi as parameter in integrand & limit subfunctions
FF(k) = quad2d(.... Calling on these subfunctions ....)
end
end
Then outside, the F function is to be called by quad, quadl, or quadgk to integrate this cross section F from c to d, and in so doing the vector X is repeatedly passed automatically to F so as to cover that interval.
Roger Stafford
