# How to set vector limits when doing an integration in Matlab?

1. Sep 23, 2011

### horminal

How to set "vector limits" when doing an integration in Matlab?

I come across a trouble when I tried to set the limits of the integration as vector:

%__________________________________________%
b=1:3;
%__________________________________________%

Then Matlab says:

??? Operands to the || and && operators must be convertible to logical scalar values.

if abs(h) < hmin || c == a || c == b

Error in ==> quadv at 75
[Q2,fcnt,warn2] = ...

Although quadv allows the integrand to be a vector, it seems Matlab does not allow the integration LIMITS to be a vector anyway. (In the above example, it means I cannot set the integration limits as (b, b+20) because b is a vector.)

I could have use the "for" loop as an alternative:

%__________________________________________%
b=1:3; c=b;
for i=1:numel(b)
c(i) = quadv(@(x) x.^2+b(i), b(i), b(i)+10);
end
%__________________________________________%

However, this will significantly increase the time needed to run the program because in this case all the integrations are not done simultaneously, and therefore a lot of time is wasted in doing the "for" loop.

Thus, does anyone have any suggestion in setting the integration limits as vectors?

(P.S. The above integrand is a simple example, while I am practically handling a much more complicated integrand.)