# I am trying to use the trapezoidal rule to compute the flow rate of fluid through a pipe.

3 views (last 30 days)
Connor Mondock on 14 Apr 2022
Commented: Torsten on 14 Apr 2022
clear
% Velocity distribution function of the pipe
v = 3.9*(1-r./r0).^n;
% Area = pi*r^2
% dA = 2*pi*r dr
% Q = V dA dr
% Value of exponent in velocity distribution function
n = 1/5;
% Value of radius in the pipe (cm)
r0 = 6;
% Range over which the integral is to be performed
r = [0,6];
% Now using the trapz method
Q1 = 2.0*pi*trapz(r,v)
It spits out an error after the initialization of the velocity distribution function saying it doesn't recognize the variable 'r', but I don't understand because I stated r as a variable below that.
##### 2 CommentsShowHide 1 older comment
VBBV on 14 Apr 2022
clear
% Velocity distribution function of the pipe
% Area = pi*r^2
% dA = 2*pi*r dr
% Q = V dA dr
% Value of exponent in velocity distribution function
n = 1/5;
% Value of radius in the pipe (cm)
r0 = 6;
% Range over which the integral is to be performed
r = [0,6];
v = 3.9*(1-r./r0).^n;
% Now using the trapz method
Q1 = 2.0*pi*trapz(r,v)

Alan Stevens on 14 Apr 2022
I think it needs to be more like this:
% Velocity distribution function of the pipe
% Area = pi*r^2
% dA = 2*pi*r dr
% Q = V dA dr
% Value of exponent in velocity distribution function
n = 1/5;
% Value of radius in the pipe (cm)
r0 = 6;
% Range over which the integral is to be performed
dr = r0/1000;
r = 0:dr:r0;
v = 3.9*(1-r./r0).^n;
% Now using the trapz method
Q1 = 2.0*pi*trapz(v)*dr
Q1 = 122.5092
% True value
vfn = @(r) 3.9*(1-r/r0).^n;
Q2 = 2*pi*integral(vfn,0,r0)
Q2 = 122.5221
Torsten on 14 Apr 2022
To get the volume flow rate, the correct integral should be
Vdot = 2*pi*integral_{r=0}^{r=r0} r*v(r ) dr
not
Vdot = 2*pi*integral_{r=0}^{r=r0} v(r ) dr
You can already see this when you consider the unit of Vdot, namely m^3/s (the last integral has m^2/s as unit).

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by