# Optimizing computing double integrals by elementwise matrix operations

조회 수: 7 (최근 30일)
Bart Boesman 2012년 8월 14일
Hi all,
I wrote my own function to calculate the double integral of a function, here referred to as 'fun(x,y)' between the boundaries x=[a,b] and y=[c,d]:
--------
function [ I ] = mydblquad( fun,a, b, c, d )
%MYDBLQUAD Summary of this function goes here
% Detailed explanation goes here
end
---------
However, as the function I have to integrate is also function of two parameters 'n' and 'm', and as I have to compute this integral over a big set of values for 'n' and 'm', it becomes computationally ineffecient to compute all the integrals in two for-loops over 'n' and 'm'. Is there another possibility, such as computing dblquad not on one function, but on a set of functions arranged in a matrix depeding on 'n' and 'm'? A first try-out did not work.
What I would like to get is something like: I( n x m ) = mydblquad ( F( n x m) ), whereby you integrate over x and y
Thanks,
Bart

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

### 채택된 답변

Sean de Wolski 2012년 8월 14일
If you are using R2012a, consider using integral2
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Bart Boesman 2012년 8월 14일
I use both R2012a and R2011b. I used this quad function because I have to integrate from -Inf to Inf. Is there an alternative for R2011b?

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

### 추가 답변 (1개)

Bart Boesman 2012년 8월 16일
Hi,
As far as I've tried, using integral2 does not solve to problem. As I suspected you can't input a matrix to the function. Any other ideas to optimize this integral loops?
Thanks,
Bart
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Mike Hosea 2012년 8월 21일
편집: Mike Hosea 2012년 8월 21일
What you are trying to do requires a lot of work, and it is going to take some time. The computational efficiency of loops is NOT the problem. The problem is the problem. You can't speed this sort of thing up by vectorizing it. You can, however speed it up by parallelizing it, and it sounds to me like your problem is what we call "embarrassingly parallel".

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

### 카테고리

Help CenterFile Exchange에서 Adding custom doc에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by