How to evaluate this triple Integral?
이전 댓글 표시
I want to evaluate the triple integral of dxdydz using 'integral3'. But the only code my intuition has helped me it this:
g = @(x,y,z) 1
u = integral3(g,1,2,1,3,1,4)
But this results in errors. Please help me create the correct code.
채택된 답변
추가 답변 (1개)
Steven Lord
2018년 4월 26일
From the description of the fun input argument in the integral3 documentation: "Integrand, specified as a function handle, defines the function to be integrated over the region xmin ≤ x ≤ xmax, ymin(x) ≤ y ≤ ymax(x), and zmin(x,y) ≤ z ≤ zmax(x,y). The function fun must accept three arrays of the same size and return an array of corresponding values. It must perform element-wise operations."
Your function does not return an array the same size as the input arrays. Torsten's approach works (as long as x must be finite) but it would be easy (if there is no comment explaining why you're subtracting x from x) for someone to "optimize" that command by eliminating the "x-x". I recommend being a bit more explicit:
g = @(x, y, z) ones(size(x));
integral3(g, 1, 2, 1, 3, 1, 4)
댓글 수: 3
Can you explain why
g = @(x, y, z) ones(numel(x),1);
integral3(g, 1, 2, 1, 3, 1, 4)
does not work ?
Steven Lord
2018년 4월 27일
It would work, if integral3 were guaranteed to pass three column vectors into the integrand function.
All integrand3 says is that the integrand function must accept three arrays of the same size. Those three arrays could be scalars, row vectors, column vectors, matrices, or N-dimensional arrays. Having the same number of elements is not sufficient. The output of the integrand function must be exactly the same size and shape as the inputs.
Torsten
2018년 4월 27일
I see - thank you very much.
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!