Filter löschen
Filter löschen

Integral2 and anonymous function in a matrix

4 Ansichten (letzte 30 Tage)
Zaharaddeen Hussaini
Zaharaddeen Hussaini am 12 Nov. 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);

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 12 Nov. 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 Kommentar
Zaharaddeen Hussaini
Zaharaddeen Hussaini am 13 Nov. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by