# how can I evaluate a four fold integral with four variables numerically ?

18 views (last 30 days)

Show older comments

### Accepted Answer

Mike Hosea
on 23 Sep 2014

Edited: Mike Hosea
on 23 Sep 2014

There's one thing that people often find difficult: the requirement that the integrand accepts arrays and returns arrays, operating element-wise.

integral(@(x)integral3(@(y,z,w)f(x,y,z,w),ymin,ymax,zmin,zmax,wmin,wmax),xmin,xmax,'ArrayValued',true)

For smooth integrands over finite regions, a double integral of a double integral is usually a lot faster

integral2(@(x,y)arrayfun(@(x,y)integral2(@(z,w)f(x,y,z,w),zmin,zmax,wmin,wmax),x,y),xmin,xmax,ymin,ymax)

##### 5 Comments

Mike Hosea
on 29 Sep 2014

You can't use integralN, but you should be able to do this:

quad2d(@(x,y)arrayfun(@(x,y)quad2d(@(z,w)f(x,y,z,w),zmin,zmax,wmin,wmax),x,y),xmin,xmax,ymin,ymax)

If your version is so old that you don't have QUAD2D, you can try this with DBLQUAD, but I don't recommend it. BTW, depending on how x and y are used in f(x,y,z,w), you might need to expand those arguments manually like so:

quad2d(@(x,y)arrayfun(@(x,y)quad2d(@(z,w)f(x*ones(size(z)),y*ones(size(z)),z,w),zmin,zmax,wmin,wmax),x,y),xmin,xmax,ymin,ymax)

### More Answers (1)

Roger Stafford
on 22 Sep 2014

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!