MATLAB: How to calculate numerically an integral of 2 integral which the outer integral depends on the upper bound of the inner integral

integrationMATLABnumerical integration

Hi,
I have the following integral which I try to solve:
In that integral, all the variables are known (acctually E is a vector which I want to solve it for each of its cells, but its ok for one value and I can iterate that process).
The upper integral has x in the upper bound which mean thta it should yield a function of x, and then we have the lower function which is function of x and depens on the answer of the upper integral. the bounds of the lower integral are known (if E is a vector, then for each value there is different WD – but as I meantioned, its also ok for single value of E).
Can you help me with solving that? I tried using syms variables and symfunc but I couldn't get an answer and it became really complicated (the best I got as value is NaN, but I know that is has an answer).
Thans!

Best Answer

Try this
An = 1;
Bn = 0.5;
C = 2;
E = 1;
Ap = 0.3;
Bp = 0.1;
upper_int = @(x) integral(@(x_) An*exp(-Bn./(C*x_-E-Ap.*exp(-Bp./(C*x_-E)))), 0, x);
F = @(Wd) integral(@(x) An*exp(-Bn./(C*x-E)).*exp(-upper_int(x)), 0, Wd, 'ArrayValued', 1);
WD = linspace(0, 0.49, 50);
Fv = arrayfun(F, WD); % compact for-loop
semilogy(WD, Fv)