Integral2 and anonymous function in a matrix

2 visualizaciones (últimos 30 días)
Zaharaddeen Hussaini
Zaharaddeen Hussaini el 12 de Nov. de 2017
Comentada: Zaharaddeen Hussaini el 13 de Nov. de 2017
I cannot seem to get integration over a function right. Any explanation why the section of code doesn't run. Even after changing ymax to scalar, matrix exceed dimension error is alway there.
lxx = 2 * RR;
lyy= RH.* cos(eT); % et is [35*6] matrix
sigma_tot = sqrt((D*(0.0045.^2+0.-0025.^2+sigma_bq.^2+0.0065.^2))); % sigma_tot returns a [35*6] matrix
fun = @(lx,ly) exp ( - ((lx.^2 + ly.^2)./(2*sigma_tot.^2)));
int_i = integral2(fun,0,lxx,0,lyy);

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Nov. de 2017
You indicate that sigma_tot is 35 x 6, and fun uses sigma_tot so fun returns a 35 x 6 matrix.
Integral2 can only integrate scalar functions.
"The function fun must accept two arrays of the same size and return an array of corresponding values. It must perform element-wise operations."
To operate over the entire sigma_tot array to get a 35 x 6 output, you will need to arrayfun over sigma_tot:
fun = @(lx,ly, sigtot) exp ( - ((lx.^2 + ly.^2)./(2*sigtot.^2)));
int_i = arrayfun(@(sigtot) integral2( @(x,y) fun(x,y,sigtot),0,lxx,0,lyy), sigma_tot);
  1 comentario
Zaharaddeen Hussaini
Zaharaddeen Hussaini el 13 de Nov. de 2017
Thanks. Had no idea Integral2 can only integrate scalar functions and would never have discovered arrayfun. I take it I do the same thing for argument lyy which is a also a matrix of equal size.
lyy= RH.* cos(eT); % et is [35*6] matrix

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by