Clear Filters
Clear Filters

Multiple function calls requiring vectorised expressions.

1 view (last 30 days)
This is an example of a problem which arose for me today. I found an ugly workaround in my specific case, but I would like to know if there is some general good way of handling the problem. So I tried to make an example which is cleaner so I hope makes more sense.
Assume I have some function f(x,y,z), I want to define g(x,y)=int_a^b f(x,y,z) dz, and h(x)=int_p^q g(x,y) dy, which can not be done analytically. I want the integrals to be evaluated numerically, which is easily achieved at the first level by using the Integral function.
This requires the function to accept vector values in z, but for the next level it requires simultaneously to accept vector values in y. This does not seem achievable in general since the vectors can be of different length. Is there a nice trick or does one need to find a specific work around depending on the case, i.e. here defining it using integral2.

Answers (1)

Sean de Wolski
Sean de Wolski on 22 Sep 2014
It sounds like you might be able to use bsxfun to apply the operation to the two separate dimensions. Consider:
>> bsxfun(@plus,1:3,(1:2).')
If you write what you have above in code it might help us further understand it.

Categories

Find more on Application Deployment 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!