How can I find Volume integration of velocity
2 views (last 30 days)
Show older comments
I am trying to perform volume integration of velocity. These data are random but within a certain range.
x is from -10 to 30, y and z is from -1 to 1 and U is from 0 to 1.
My code is as follows-
data= xlsread('Re_100_dh_0.1.xlsx');
U= data(:,1); % (:,1) means all first columns
x= data(:,2); % (:,2) means all second columns
y = data(:,3); % (:,3) means all third columns
z = data(:,4); % (:,4) means all fourth columns
result=trapz(x,trapz(y,trapz(z,U,3),2),1); %% My question is here.
These yields an error showing, Length(x) must equal the length of the DIM'th dimendion of Y.
How can I cope with this?
0 Comments
Answers (1)
Walter Roberson
on 18 May 2019
U = data(:,1); % (:,1) means all first columns
So U is a column vector
z = data(:,4); % (:,4) means all fourth columns
so z is a column vector with the same size as U
trapz(z,U,3)
requests that the values in z have a trapazoid summation done along the third dimension, using the content of U as the coordinates along the third dimension. However we know that z is a column vector, so its length along the third dimension is 1, which does not match the length of U.
If it happens that x, y, z form a regular cuboid with value U at each point... then you do not have enough U values.
So we have to deduce that you do not have a regular grid: you have scattered points. You cannot use trapz to meaningfully do volume integration in such a case.
Perhaps you could reshape your x, y, z to form a regular cuboid. If so then you would need to know the order they are in, and you would need to know the marginal lengths of the edges. You would then reshape, such as
marglen = [17 11 16];
X = reshape(x, marglen);
Y = reshape(y, marglen);
Z = reshape(z, marglen);
UU = reshape(U, marglen);
and once that was done it would become meaningful to start using trapz over the various dimensions,
trapz( squeeze(X(:,1,1)), trapz(squeeze(Y(1,:,1)), trapz(squeeze(Z(1,1,:)), UU, 3), 2), 1)
Here the intent of the squeeze() section is to extract the marginal unique values for each of the directions.
4 Comments
Walter Roberson
on 19 May 2019
Have you considered
countx = length(unique(x));
county = length(unique(y));
countz = length(unique(z));
You overwrite your countx, county, countz. The values you assign multiply to 3573409800 . For the vector 1 to that, allow 8 bytes per entry, giving 28587278400 bytes, which is about 27 gigabytes. Writing the code that way also implies that x and y and z and U are also all at least that large, getting you up to over 108 gigabytes.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!