How can I compute the following triple integral for a function handle that is expressed by x(1), x(2), x(3)?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Steven Lord
2021년 10월 20일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!