Numerical integration of area

3 visualizaciones (últimos 30 días)
user20912
user20912 el 30 de Jul. de 2024
Comentada: user20912 el 30 de Jul. de 2024
Hi,
I know this must be so easy but I'm confused. I have a section such as this:
I have both variables depth and distance as vectors:
>> whos depth rotx
Name Size Bytes Class Attributes
depth 69x1 552 double
rotx 69x1 552 double
What is the right way to compute the section area?
Thanks!

Respuesta aceptada

John D'Errico
John D'Errico el 30 de Jul. de 2024
Editada: John D'Errico el 30 de Jul. de 2024
The region in color? The integral will be negative, or course, since depth is entirely negative.
But you perform such an integration using trapz. The integration you need to do is the difference between the lower limit at any x, and the upper limit, which is 0. As such,
trapz(depth,0-rotx) % Not this, of course.
Read the help for trapz.
Edit: (Duh) Repairing my sleepy code:
trapz(rotx,0-depth)
  3 comentarios
John D'Errico
John D'Errico el 30 de Jul. de 2024
Editada: John D'Errico el 30 de Jul. de 2024
Of course, I did. Is that not what I wrote? ;-)
I admit, I always forget, since trapz tries to be tricky. You can call it with 1 or 2 arguments. With 2 arguments, you call it as trapz(x,y), but with only one argument, it is just trapz(y). Personally, I never liked the way they did it.
help trapz
TRAPZ Trapezoidal numerical integration. Z = TRAPZ(Y) computes an approximation of the integral of Y via the trapezoidal method (with unit spacing). To compute the integral for spacing different from one, multiply Z by the spacing increment. For vectors, TRAPZ(Y) is the integral of Y. For matrices, TRAPZ(Y) is a row vector with the integral over each column. For N-D arrays, TRAPZ(Y) works across the first non-singleton dimension. Z = TRAPZ(X,Y) computes the integral of Y with respect to X using the trapezoidal method. X can be a scalar or a vector with the same length as the first non-singleton dimension in Y. TRAPZ operates along this dimension. If X is scalar, then TRAPZ(X,Y) is equivalent to X*TRAPZ(Y). Z = TRAPZ(X,Y,DIM) or TRAPZ(Y,DIM) integrates across dimension DIM of Y. The length of X must be the same as size(Y,DIM)). Example: Y = [0 1 2; 3 4 5] trapz(Y,1) trapz(Y,2) Class support for inputs X, Y: float: double, single See also SUM, CUMSUM, CUMTRAPZ, INTEGRAL. Documentation for trapz doc trapz Other uses of trapz codistributed/trapz gpuArray/trapz
So, yes. I meant to write
trapz(rotx,0-depth)
And apparently, my fingers got in the way of my head.
user20912
user20912 el 30 de Jul. de 2024
I feel it is easy but confuses me every time. Thanks for you help :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by