integration with limits using an array

I am trying to integrate an equation and it works when I do not have limits but when I add them it does not work.
u_wake is a 1x56 array, rho is a constant and 0.07 and 0.13 are the limit boundaries.
This works when I use this:
Drag = rho*trapz(u_wake.*(21.15-u_wake));
But not when I do this:
Drag = rho*trapz(u_wake.*(21.15-u_wake),0.07,0.13);

3 comentarios

the cyclist
the cyclist el 6 de Oct. de 2022
Editada: the cyclist el 6 de Oct. de 2022
It would be helpful if you uploaded the data, instead of just describing it. You can use the paper clip icon in the INSERT section of the toolbar.
Also, you should be more specific than saying, "it does not work". Does the code give an error message? (If so, what is the complete error message?) Or, do you just get a result you do not expect?
James Keiser
James Keiser el 6 de Oct. de 2022
Editada: James Keiser el 6 de Oct. de 2022
I cannot upload the data because it is 56 files and I am only allowed to upload 10. The data is 56 numbers all below 21.15 .
The error code is:
Error in wake_scan_sample (line 35)
Drag = rho*trapz(u_wake.*(21.15-u_wake),0.07,0.13);
the cyclist
the cyclist el 6 de Oct. de 2022
It's unclear to me why you can't just upload u_wake, which is just a 1x56 vector.
Also, that is not the complete error message, which I am guessing looks something more like ...
Error using matlab.internal.math.getdimarg
Dimension argument must be a positive integer scalar within indexing range.
Error in trapz>getDimArg (line 90)
dim = matlab.internal.math.getdimarg(dim);
Error in trapz (line 36)
dim = min(ndims(y)+1, getDimArg(dim));
Error in wake_scan_sample (line 35)
Drag = rho*trapz(u_wake.*(21.15-u_wake),0.07,0.13);

Iniciar sesión para comentar.

Respuestas (1)

the cyclist
the cyclist el 6 de Oct. de 2022

0 votos

Looking at the documentation for trapz, it doesn't seem like the syntax you are trying to use is valid.

2 comentarios

James Keiser
James Keiser el 6 de Oct. de 2022
What would recommend to fix the syntax?
I assume that u_wake is the "y" value of the integral. Are 0.07 and 0.13 the endpoints of the "x" value? Are the values of u_wake at evenly spaced points along x? Then
Drag = rho*trapz(linspace(0.07,0.13,length(u_wake)),u_wake.*(21.15-u_wake));
should calculate what you want. For example,
% I just made up some u_wake and rho data
u_wake = sort(rand(1,56));
rho = 1;
Drag = rho*trapz(linspace(0.07,0.13,length(u_wake)),u_wake.*(21.15-u_wake))
Drag = 0.5618

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2022b

Preguntada:

el 6 de Oct. de 2022

Comentada:

el 6 de Oct. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by