Optimized solution for a function with two integrals which depend on each other

Hi everyone,
I have already created a code which numerically calculates the following function:
As you can see the inner integral depends on the outer one via 'q'. The inner integral is solved with the integral command
G_inner_integral = integral (@(y) inner_function(y),0,2*pi,'ArrayValued',true);
for every iteration inside a for loop, in which via trapezoidal rule the outer integral and therefore the whole function is approximated.
Is it possible to discard the for loop and solve it in a more clever way, maybe even within a few commands (with the help of functions like cumtrapz, trapz, or integral)? I have tried a some of those approaches but with no desired result.
P.S Prefer the numerical solution as the functions inside the integrals are quite complex and therefore time consuming for any analytical approach.
Thank you in advance

 채택된 답변

Torsten
Torsten 2018년 6월 26일
Use "integral2" instead of "integral".
Best wishes
Torsten.

댓글 수: 2

Hi Torsten,
Thank you for the answer, although integral2 is a bit tricky to use it here, as I dont have a function with two variables (e.q f(x,y)) in order to first integrate lets say over x and then over y.
Insted, on each discrete step of trapezoidal approximation from
both values q = qL & q = qL+dq are given to
in order for this integration to be conducted first. Then, the external one should be done cumulatively and therefore integral2 doesnt seem like an option.
Of course if you have a ready to use suggestion, I will certainly thoroughly examine it, but my so far knowledge tells me the opposite.
I don't understand your comment.
Your function of two variables is given by
f(x,y) = x^3*C(x)*(E(x*v*cos(y))/((1-nu^2)*sigma0))^2
and has to be integrated between
x=ql to x=q and y=0 to y=2*pi
This is a typical application of integral2.
Best wishes
Torsten.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

질문:

2018년 6월 26일

댓글:

2018년 6월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by