tags:

views:

72

answers:

4

hi, i want to solve this problem:

alt text

i don't want to use "int", i want to use "quad" family (quad,dblquad,triplequad) but i can't. can you help me?

+2  A: 

The integral you show is

  1. Analytically solvable: always do analytically what you can

  2. ?equal to a number: constant expressions should be eliminated from numerical calculations

  3. not easy to get calculated in MATLAB (or very correct).

You can use cumtrapz to integrate over each variable alone, and call trapz the final integration. Remember that this will blow up the error on any problem that is more complicated than the simple sum of linear functions.

Mathematica is more suited to nD integrations, if you have access to that.

rubenvb
A: 

matlab can do symbolic integration

>> x = sym('x'); y = sym('y'); z = sym('z'); u = sym('u'); v = sym('v'); 
>> int(int(int(int(int(x+y+z+u+v,1,5),-2,3),0,1),-1,1),0,1)

ans =

180
second
Only if you have the symbolic package...
Kena
A: 

Just noticed you want to do numeric, not symbolic integration

If you look at the source of dblquad and triplequad

>> edit dblquad

you see that they just call the lower versions. it should be possible for you to add a quadquad and a quintquad (or recursively an n-quad)

second
+3  A: 

I assume that your real problem is more complex than this trivial one. The best solution is just to use a symbolic integral. Why is numerical integration difficult?

Numerical integration in ONE dimension typically requires on the order of say 100 function evaluations. (The exact number will be very dependent on the accuracy required, the limits, etc.) This makes a 2-d integral typically require on the order of 100^2 = 10000 function evals. So an adaptive, 5-d integral will require on the order of 100^5 = 1e10 function evaluations. (This is only a very rough order of magnitude estimate here.) My point is, you simply don't want to do that!

Better is to reduce the problem in complexity. If your integral is separable (as is this one) then do so! Reduce a 5-d problem into multiple 1-d problems.

Also, in many cases I see people wanting to do a numerical integration of a Gaussian PDF. See that this is easily solved using a call to erf or erfc, coupled with a transformation. The point is that in many cases special functions are defined to greatly reduce the complexity of a problem.

I should add that in many cases, the key to solving a difficult problem in mathematics is to use mathematics to reduce the problem to something simpler. If you can find a way to reduce the dimensionality of your problem just a bit, it will become much more tractable.

woodchips

related questions