I have a simple question that I wasn't able to find an answer to. I have a function
x is some vector, for example:
function f=f(x) f=x.^4; end
Then I want to integrate with bounds as vectors:
x=1:0.1:10; x_0=2*ones(size(x)); g=integral(@f,x_0,x);
and I want to get
g as a vector
g(i)=integral(@f,x_0(i),x(i)). However, this will return an error that the bounds have to be scalars.
Obviously I can use a loop:
x=1:0.1:10; x_0=2*ones(size(x)); for i=1:length(x) g(i)=integral(@f,x_0(i),x(i)); end
but that can be very inefficient if I have big vectors that are repeatedly integrated.
Is there a simple efficient way to do this vectorized without a loop?