Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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)

Risposta accettata

Steven Lord
Steven Lord il 20 Ott 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.

Più risposte (0)

Categorie

Scopri di più su Numerical Integration and Differential Equations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by