Integration of a Multiple Anonymous Function Which Depends on Parameters of an Integral

1 回表示 (過去 30 日間)
Sean Raffetto
Sean Raffetto 2016 年 2 月 10 日
コメント済み: Walter Roberson 2016 年 2 月 11 日
Dear All,
I have a function that needs to be integrated and depends on parameters of an integral like:
int = @(x,Rad,K) (1+0.25.*sin((P/5).*x.*sin(Rad)).*exp(-1i.*2.*x.*cos(Rad).*K'))
%where P is pi to a certain number of digits
%Rad is a 721x1 vector of angles 0-360 in radians (so 0-6.28 in steps of 0.0087)
%K is a 37x1 vector of wave numbers (2.9342 to 4.3979 in steps of 0.0406)
The integration range is from -6.096 to 6.096 and the integration variable is x. I want to use:
q = integral(@(Rad,K)int@(x),-L/2,L/2,'ArrayValued',true);
But it hasn't been working. I want "q" to output a 721x37 matrix. The function works without having "@(Rad,K)", "@(x)", and "sin(Rad)" in the function, but I need "sin(Rad)" in the function to obtain the correct values in the 721x37 matrix. What do I need to add/what do I need to change to make this integral/function work? I also want to use the "integral" function since I have 2015b and that is what Matlab 2015b recommends, not quadv since that will disappear soon.

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 2 月 10 日
q = integral(@(x)int(x, Rad, K),-L/2,L/2,'ArrayValued',true);
  6 件のコメント
Sean Raffetto
Sean Raffetto 2016 年 2 月 11 日
Ok. How can I make this work w/o using 'ArrayValued'/what do I need to add/change? Thanks.
Walter Roberson
Walter Roberson 2016 年 2 月 11 日
[RadR, KR] = ndgrid(Rad, K);
int = @(x) (1+0.25.*sin((P/5).*x.*sin(RadR)).*(exp(-1i.*2.*x.*cos(RadR).*KR)));
q = integral(int, -L/2,L/2,'ArrayValued',true);
Unless, that is, K is complex; if so then you might need conj(K) in the ndgrid() call, to match the conjugate complex transpose you originally had.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by