How can I compute the following triple integral for a function handle that is expressed by x(1), x(2), x(3)?

1 visualización (últimos 30 días)
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)

Respuesta aceptada

Steven Lord
Steven Lord el 20 de Oct. de 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)
Warning: Inf or NaN value encountered.
Warning: The integration was unsuccessful.
f_int = NaN
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)
Warning: Inf or NaN value encountered.
Warning: The integration was unsuccessful.
f_int = NaN
At some point your integrand boils down to 0*Inf I believe. You will need to determine how to handle that.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by