MATLAB: How to solve integral of vector

How do I use the integral function on a vector? I tried this:
fun=@(s)expm(Ae*s)*h
q=@(t)integral(fun,0,t)
Ae is a matrix and h is a vector.

Best Answer

You have to specify ‘'ArrayValued',true’ in the integral call. To integrate over a vector ‘t’, use the arrayfun function:
Ae = randi(9,3); % Create ‘Ae’
h = randi(9,3,1); % Create ‘h’
fun=@(s)expm(Ae.*s)*h;
q=@(t)integral(fun,0,t, 'ArrayValued',true) % Specify 'ArrayValued',true
Q1 = arrayfun(q, (0:5), 'UniformOutput',false); % Integrate Over Vector ‘t’