MATLAB: Need help in evaluating integral with quad

MATLABquad

Hi,I need to numerically evaluate an integral,for different values of a parameter,and store these in a vector.The integral is:
f(theta)=integral of(exp(-2x)*sin(2xsin(theta/2))dx, x running from 0 to 2 I am trying to attempt this with quad using the anonymous function approach.I coded it thus,
theta=0.01:0.1:2*pi-0.01;
f=@(x,th)(exp(-0.5*x)*sin(x*2*sin((th)/2)));
for i=1:length(theta)
th=theta(i);
born(i)=quad(@(x)f(x,th),0,2);
end;
I cannot understand why I get the error
??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> @(x,th)(exp(-0.5*x)*sin(x*2*sin((th)/2)))
Error in ==> @(x)f(x,th)
Error in ==> quad at 77
y = f(x, varargin{:});
Error in ==> born_integral at 8
born(i)=quad(@(x)f(x,th),0,2);
Is there a way to make it work with quad or a similiar function ? (I'll try numerical integration algorithms as a last resort) Thanks in advance.

Best Answer

Just a dot missing from the second line, before *sin
theta=0.01:0.1:2*pi-0.01;
f=@(x,th)(exp(-0.5*x).*sin(x*2*sin((th)/2)));
for i=1:length(theta)
th=theta(i);
born(i)=quad(@(x)f(x,th),0,2);
end
Related Question