Integral over an integral without analytical solution
Mostra commenti meno recenti
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!
Risposte (2)
Walter Roberson
il 14 Lug 2016
0 voti
You should be using integral2() . You can use functions for the lower and upper bounds of the second variable.
1 Commento
Stefan Brehm
il 15 Lug 2016
Stefan Brehm
il 16 Lug 2016
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!