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.
댓글 수: 0
답변 (1개)
Walter Roberson
2016년 2월 10일
q = integral(@(x)int(x, Rad, K),-L/2,L/2,'ArrayValued',true);
댓글 수: 6
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!