Azzera filtri
Azzera filtri

Integral2 and anonymous function in a matrix

4 visualizzazioni (ultimi 30 giorni)
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);

Risposta accettata

Walter Roberson
Walter Roberson il 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 Commento
Zaharaddeen Hussaini
Zaharaddeen Hussaini il 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by