Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Sep 23, 2011 #1
    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;
    c= quadv(@(x) x.^2+b, b, b+20);
    %__________________________________________%

    Then Matlab says:

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

    Error in ==> quadv>quadstep at 141
    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.)
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: How to set vector limits when doing an integration in Matlab?
Loading...