필터 지우기
필터 지우기

4D integration numerical evaluation

조회 수: 10 (최근 30일)
R yan
R yan 2015년 2월 12일
댓글: TheStranger 2023년 1월 17일
Hi
I am trying to numerically evaluate a 4D integral of the form:
\int\int\int\int K(x,y,t,s)h_m(x)h_n(y)h_p(t)h_q(s)dxdydtds, limits of integral is 0 to 1.
where h is a function of single variable.
thanks
  댓글 수: 1
Star Strider
Star Strider 2015년 2월 12일
See the documentation for integral. Depending on your version of MATLAB, you may need to search for the correct function. In previous versions, the quad function and its friends did numerical integration of functions.
You will need to iterate your integration four times, once for each variable.
Another option is trapz if you have already evaluated your function over a 4D grid and you want to use trapezoidal integration. You will have to integrate it over each dimension, so four times for it as well.

댓글을 달려면 로그인하십시오.

채택된 답변

Mike Hosea
Mike Hosea 2015년 2월 13일
Well, you can try integralN from the file exchange. I wrote that little ditty just so I wouldn't have to keep explaining the nuances of how to nest calls to integral functions. The call would look like
integralN(@(x,y,t,s)K(x,y,t,s).*h_m(x).*h_n(y).*h_p(t).*h_q(s),0,1,0,1,0,1,0,1);
But you might gain some advantage here by nesting the calls yourself, since you can factor out a couple of functions easily.
inners = @(x,y)h_m(x).*h_n(y).*integral2(@(t,s)K(x*ones(size(t),y*ones(size(t),t,s).*h_p(t).*h_q(s),0,1,0,1);
inner = @(x,y)arrayfun(inners,x,y);
Q = integral2(inner,0,1,0,1);
I don't have time to test that right now. Give it a try. Note that I'm assuming K, h_p and h_q can be called with array inputs so that they compute array outputs, the function values computed element-wise. Usually this means using .* instead of *, ./ instead of /, and .^ instead of ^, but it isn't always quite that simple.
  댓글 수: 4
John D'Errico
John D'Errico 2015년 2월 20일
What people do not realize is just how much computation a 4-times nested integral involves.
A single numerical integral will often require 100 to perhaps 1000 function evaluations, or more. This depends on how complex is the function. These n-d integrators typically treat the next outer integral as if the inner integral is just a general function, to be then integrated. So we can visualize that a 4-times nested integral will typically require something on the order of 100^4=1e8 function evaluations, OR MORE. No matter how fast your computer, calling for 1e8 kernel evaluations will take some time.
TheStranger
TheStranger 2023년 1월 17일
@John D'Errico true, my colleague who used to approximate many-dimensional integral said that a possible solution is to estimate it using Monte-Carlo, as directly putting a whole mesh of data values into RAM, most likely, is impossible on a typical PC that is not a supercomputer.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by