Need help in evaluating integral with quad

13 ビュー (過去 30 日間)
Raghav
Raghav 2011 年 3 月 10 日
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 件のコメント
John D'Errico
John D'Errico 2011 年 3 月 10 日
Quad IS a numerical integration algorithm!!!!!

サインインしてコメントする。

採用された回答

Paulo Silva
Paulo Silva 2011 年 3 月 10 日
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

その他の回答 (1 件)

Matt Fig
Matt Fig 2011 年 3 月 10 日
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);

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by