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

1 visualización (últimos 30 días)
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.

Respuestas (1)

Walter Roberson
Walter Roberson el 10 de Feb. de 2016
q = integral(@(x)int(x, Rad, K),-L/2,L/2,'ArrayValued',true);
  6 comentarios
Sean Raffetto
Sean Raffetto el 11 de Feb. de 2016
Ok. How can I make this work w/o using 'ArrayValued'/what do I need to add/change? Thanks.
Walter Roberson
Walter Roberson el 11 de Feb. de 2016
[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.

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by