Double Integration. Function handle use
Show older comments

I have been trying hard to get to represent the following equation on matlab.
int_c = 1./((2.*pi.*sigma_tot.^2));
fun = @(lx,ly, sigtot) exp ( - ((lx.^2 + ly.^2)./(2*sigtot.^2 )));
lxx = 2 * RR;
lxx_min = -lxx./2;
lxx_max = lxx./2;
lyy_min = @(gamma)(-(RH.* cos(gamma))./2);
lyy_max = @(gamma)((RH.* cos(gamma))./2);
int_i = arrayfun(@(sigtot) integral2( @(xi,yi) fun(xi,yi,sigtot),lxx_min,lxx_max,lyy_min,lyy_max), sigma_tot);
This is what I have so far. Please bear in mind that the following equation was executed inside a loop. sigma_tot and gamma changes with every increasing loop count.
It does provide me with results but my main question is why does lyy_min and lyy_max have to have the function. Without it I will get an error. The true definition is supposed to be
lyy_min =(-(RH.* cos(gamma))./2);
lyy_max = ((RH.* cos(gamma))./2);
However, the code would not run that way. So can anyone pls tell me if what I represented make sense.
Thanks
6 Comments
Steven Lord
on 5 Jun 2018
Your code does not define sigma_tot, RR, RH, or gamma (in your "true definition" of lyy_min and lyy_max). What are their sizes and types?
When you try to use your "true definition", you said your code "would not run."
- Does that mean you received an error? If so, please post the FULL text of that error message (everything displayed in red text.)
- Did you receive a warning? If so, please post the FULL text (everything displayed in orange text.)
- Does it do something else? If so, please describe in detail what happens.
John D'Errico
on 5 Jun 2018
Let me ask it this way.
Are the limits on the inner integral functions of some variable? (Apparently so.)
If that is true, then why would you expect things to work if you ignore that functionality?
If you want a better answer, then you need to explain what the limits of integration are, rather than calling them (X') and (Y')
Zaharaddeen Hussaini
on 5 Jun 2018
Apologies on all the grey areas. You could evidently tell I am trying to figure my way with Matlab.
1. I should state that x' any y' are represented by lxx (with limits lxxmin and lxx_max) & lyy(lyy_min and lyy_max).
2. When I use the 'true definition' without the @(gamma) function, for lyy the error code is:
Error in StaggerUpdated_VaryingDR>@(sigtot)integral2(@(xi,yi)fun(xi,yi,sigtot),lxx_min,lxx_max,lyy_min,lyy_max)
Error in StaggerUpdated_VaryingDR (line 151)
int_i = arrayfun(@(sigtot) integral2( @(xi,yi) fun(xi,yi,sigtot),lxx_min,lxx_max,lyy_min,lyy_max), sigma_tot);
3. The reason I assumed it could work without the functionality is because I assumed all the variables in it (gamma and RH) are all variables.
Pleae note: RH and RR are scalar all through the loop and do not change value. gamma changes value with every loop.)
4. Although the code does run like this. I cannot but help think I may have just gotten lucky. Just wanted to be sure the representation of the equation made makes proper sense. Again apologies with the crude explanations. I hope I have made it a little clearer
Zaharaddeen Hussaini
on 5 Jun 2018
3* The reason I assumed it could work without the functionality is because I assumed all the variables in it (gamma and RH) are all clear and defined
John D'Errico
on 6 Jun 2018
I think what you misunderstand is that if gamma is fixed at some value, then it is fixed at the current value in your workspace. But the limits are functions of gamma. You need to write it as a function, else it will not be used as a function.
Zaharaddeen Hussaini
on 6 Jun 2018
Yes they are. Okay. Thanks for the further clarification.
Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!