Need help in evaluating integral with quad

11 Ansichten (letzte 30 Tage)
Raghav
Raghav am 10 Mär. 2011
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.
  1 Kommentar
John D'Errico
John D'Errico am 10 Mär. 2011
Quad IS a numerical integration algorithm!!!!!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Paulo Silva
Paulo Silva am 10 Mär. 2011
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

Weitere Antworten (1)

Matt Fig
Matt Fig am 10 Mär. 2011
Or, you can do it in one shot with QUADV:
th = 0.01:0.1:2*pi-0.01;
f = @(x)(exp(-0.5*x).*sin(x*2*sin((th)/2)));
born = quadv(f,0,2);

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by