For loop relative to the quad function to apply integration, which is faster?

2 次查看(过去 30 天)
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

回答(1 个)

Mike Hosea
Mike Hosea 2012-8-28
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 个评论
Mike Hosea
Mike Hosea 2012-8-28
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).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by