How to evaluate this triple Integral?
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (1)
Steven Lord
am 26 Apr. 2018
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 Kommentare
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
am 27 Apr. 2018
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
am 27 Apr. 2018
I see - thank you very much.
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!