For loop relative to the quad function to apply integration, which is faster?
2 views (last 30 days)
Show older comments
I have four integration for my problem, each is a surface integral. So basicaly, I have eight line integrals on theta and phi. The time processing is extremely slow when I am using eight nested for loops. I was wondering which is fatser to use 8 for nested loops or quad function?
If "quad" function is faster, do I then need to use "dblquad" function 4 nested times by creating four separate functions and using each one of them in a nested manner?
Thank you Regards Mohamed
0 Comments
Answers (1)
Mike Hosea
on 28 Aug 2012
I'm afraid I don't fully understand the question, but if you need to do a surface integral, use integral2. If you don't have R2012a, use quad2d. To use either of these functions, you supply an integrand function with 2 input arguments. The integrand function must be able to accept arrays (of the same size) for each of its input arguments and operate "element-wise", returning an array of corresponding function values. See "help integral2" or "help quad2d". There's more to know, but at this point I don't know what information to supply.
1 Comment
Mike Hosea
on 28 Aug 2012
BTW, if you have a triple integral, there's integral3. There's no integral4 for 4-D problems, but you can nest like so integral(@(w)integral3(@(x,y,z)fun(x,y,z,w),blah,blah,blah),a,b,'ArrayValued',true).
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!