How to perform 4D integral in matlab ?

34 views (last 30 days)
I want to calculate the integral of a bidirectional reflectance distribution function(a function with 2 direction parameters both represent by a pair of theta and phi, so it's a 4D function). Since the function is usually not easy to factor out as multiplication of lower dimensional function it's hard to use command such as "integral" or "integral2", any suggestion about this issue ?

Accepted Answer

Mike Hosea
Mike Hosea on 1 Jun 2013
The easiest way to integrate f(x,y,z,w) from a <= x <= b, c <= y <= d, e <= z <= g, and h <= w <= i is
Q = integral(@(x)integral3(@(y,z,w)f(x,y,z,w),c,d,e,g,h,i),a,b,'ArrayValued',true);
if the limits are functions of the preceding variables, i.e.:
c(x), d(x), e(x,y), g(x,y), h(x,y,z), i(x,y,z)
you will have to fix x in them as we did for the integrand:
Q = integral(@(x)integral3(@(y,z,w)f(x,y,z,w),c(x),d(x),@(y)e(x,y),@(y)g(x,y),@(y,z)h(x,y,z),@(y,z)i(x,y,z)),a,b,'ArrayValued',true);
The other, and perhaps faster way in some cases, would be to do an integral2(integral2(...)...) nesting, but this requires a bit of work to set up because of the vectorization that integral2 requires of the integrand.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!