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!