Suppose we have a function $F(\lambda) = \int\limits_{\lambda}^1 f(x) dx$, where $f(x)$ has no formula for antiderivative.
We can easily calculate it by means of build-in MATLAB functions. Let's use $f(x) =\sqrt{x}e^{-x}$ for example:
>>f = @(x) sqrt(x) .* exp(-x);
>>F = @(lambda) integral(@(x) f(x), lambda, 1);
F(0.3)
ans =
0.2028
What if we need to find $G(\mu) = \int\limits_0^{\mu} F(\lambda)d{\lambda}$ now?
I tried to use the same approach and write
G = @(mu) integral(F, 0, mu)
but MATLAB returns an error in this case. As far as I understood, MATLAB expects function handle as the first argument of an integral function, but we obtain a number instead. Is there a way to handle this problem?
Thank you for any help!
The problem appears to be that if you attempt to pass a vector to the inner "integral" function, it fails, but this is how the outer "integral" function wants to use its first argument. A simple workaround for the double (or analogously triple) integral case is to just use integral2. In your example this would be: