MATLAB: Need to use double quad function for four integration with four unknowns

dblquad function

I need to write the correct command that enables me to use the "dblquad" function to solve four integrations with four different variables.
for example: yy = dblquad(….dblquad(@myfun,0,2*pi,0,2*pi))
now the funtion myfun contains phi1,phi2,phi3,phi4 four different variables.
The command line I wrote is not yet complete and I am not sure if it is correct or not.
The myfun should it be then written as follow y = myfun(phi1,phi2,phi3,phi4)
Please I need an answer ASAP
Thank you

Best Answer

You should be using INTEGRAL2, but the solution is almost the same.
Using INTEGRAL2:
integral2(@(u,v)arrayfun(@(z,w)integral2(@(x,y)myfun(x,y,z,w),0,2*pi,0,2*pi),u,v),0,2*pi,0,2*pi)
Using DBLQUAD
dblquad(@(u,v)arrayfun(@(z,w)dblquad(@(x,y)myfun(x,y,z,w),0,2*pi,0,2*pi),u,v*ones(size(u))),0,2*pi,0,2*pi)
The INTEGRAL2 way finished in a couple of seconds with the example I gave it, DBLQUAD took 2852 seconds.
You can use QUAD2D instead of INTEGRAL2 if you don't have R2012a. If you do have R2012a, you can also do this
integral(@(x)integral3(@(y,z,w)myfun(x,y,z,w),0,2*pi,0,2*pi,0,2*pi),0,2*pi,'ArrayValued',true)
-- Mike
Related Question