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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by