Integral over an integral without analytical solution
이전 댓글 표시
Hello there,
I'm facing the following challenge:
I have a nested integral without analytical solution wich depends on the same variable as the outer integral. Testing the integral routine with a similar problem (but with analytical solution) yields out that the result is wrong.
The similar problem looks like: Integral dx(Integral dx x). The analytical solution gives (1/6)*x^3.
If we now assume the area of this analytical solution from 0 to 2 we expect 8/6 (round about 1.333). But what MATLAB outputs is 4.
So what happens is that first the function x is numerically integrated from 0 to 2 what gives 2 and then the result is again integrated what gives 4 (so, the integral from 0 to 2 over 2)
Here is the code for the example:
% Call of the integration
x1 = 0;
x2 = 2;
OuterInt(x1,x2)
Function for outer integral:
function [Total] = OuterInt(x1,x2)
OuterFun = @(x) InnerInt(x1,x2);
Total = integral(OuterFun,x1,x2,'ArrayValued',true);
And at last the function for the inner integral:
function [ValInnerInt] = InnerInt(x1,x2)
%x1 lower boarder; x2 upper boarder
InnerFun = @(x) x;
ValInnerInt = integral(InnerFun,x1,x2,'ArrayValued',true);
end
For instance: the inner integral should be evaluated at maximum to the current step in the integration of the outer integral.
Thanks to everybody sharing solutions and ideas with me!
답변 (2개)
Walter Roberson
2016년 7월 14일
0 개 추천
You should be using integral2() . You can use functions for the lower and upper bounds of the second variable.
Stefan Brehm
2016년 7월 16일
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!