A very good question. You need to use QUADV here instead of QUAD.
quadv(@(x) exp(x.^2).*quad(@(z) exp(z.^2),-2,x),-2,2)
QUAD expects vector inputs and outputs, and so when it goes to evaluate the inner QUAD, it sends in a vector which is why you get that error.
Notice that QUAD will error on a problem like this one here below for the same reason (but QUADV will work fine):
quad(@(x) det([x 1; 1 1]),0,1)
QUADV does it without trying to send in vectors.
Just as a sanity check, compare what you get from QUADV with what you get if you did it using TRAPZ
f = @(x) exp(x.^2).*quad(@(z) exp(z.^2),-2,x);
trapz(arrayfun(f,-2:.001:2)) * 0.001
quadv(f,-2,2)
Both answers are very similar, about 541.38.
Best Answer