MATLAB: Matrix dimentions must agree

dimensionsintegralmatrix

i want to calculate qdot for a range of x values and plot it. but it gives matrix dimensions must agree error if i use range of x values instead of single x. i tried putting dot before *. how to modify the code for x=0:0.01:0.5 and add a plot(x,qdot) in the end?
k=10;
x=0.25;
a=@(u) exp(-(k*x)./u);
q1=integral(a,0,1);
b=@(u) exp(-(0.5*k-k*x)./u);
q2=integral(b,0,1);
c=@(u,t) (1./u).*exp(-abs(k*x-t)./u);
q3=integral2(c,0,1,0,0.5*k);
qdot=2*pi*k*(1128.09*q1+1128.09*q2+3221.939*q3-2*3221.939)

Best Answer

"For scalar-valued problems, the function y = fun(x) must accept a vector argument, x, and return a vector result, y. This generally means that fun must use array operators instead of matrix operators. For example, use .* (times) rather than * (mtimes). If you set the 'ArrayValued' option to true, then fun must accept a scalar and return an array of fixed size."
In your case if your x is a vector then
a=@(u) exp(-(k*x)./u);
for any given scalar u would return a vector the same size as x, so you would need to use 'vectorized' for integral() in that case.
However, integral2() has no corresponding option.
c = @(u, t, this_x) (1./u).*exp(-abs(k*this_x-t)./u);
q3 = arrayfun(@(this_x) integral2(@(u,t) c(u,t,this_x), 0, 1, 0, 0.5*k), x);