How can I compute the following triple integral for a function handle that is expressed by x(1), x(2), x(3)?
1 view (last 30 days)
Show older comments
DIMITRIS GEORGIADIS
on 20 Oct 2021
Answered: Steven Lord
on 20 Oct 2021
I am trying to solve the following triple integral but I get an error message.
I could use x(1)=x, x(2)=y, x(3)=z, but I want to express [x,y,z] as x=[x(1),x(2),x(3)]. Any idea?
t = 15;
f = @(x) ( x(1)*(t - x(2))^x(3) ).*(x(2) <= t);
f_int = integral3(@(x) f(x), 0, Inf, 0, Inf, 0, Inf)
0 Comments
Accepted Answer
Steven Lord
on 20 Oct 2021
integral3 requires the function handle you pass in as the first input to accept three input arrays and return an output array of the same size. Your f function assumes that x is a vector with 3 elements which is incompatible with that requirement. One way to resolve this incompatibility is to use arrayfun. But that uncovers a different problem:
t = 15;
f = @(x) ( x(1)*(t - x(2))^x(3) ).*(x(2) <= t);
newF = @(x, y, z) arrayfun(@(x, y, z) f([x, y, z]), x, y, z);
f_int = integral3(newF, 0, Inf, 0, Inf, 0, Inf)
Rather than including (x(2) <= t) in the integrand, why not change the limits of integration? This doesn't avoid the NaN issue but does make the integrand simpler to debug.
t = 15;
g = @(x) ( x(1)*(t - x(2))^x(3) );
newG = @(x, y, z) arrayfun(@(x, y, z) g([x, y, z]), x, y, z);
f_int = integral3(newG, 0, Inf, 0, t, 0, Inf)
At some point your integrand boils down to 0*Inf I believe. You will need to determine how to handle that.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!