Unrecognized function or variable 'qdpfun"

1 回表示 (過去 30 日間)
Crizel Joyz Amano
Crizel Joyz Amano 2022 年 5 月 1 日
コメント済み: Crizel Joyz Amano 2022 年 5 月 2 日
% qdP.m: plot of volumetric flow rate vs. dP
clear all;
dP = -18*1.01325e5; dz = 100; rho = 1e3; mu = 1e-3; L = 1500; D = 0.154; rh = 4.57e-5; % data
x0 = [5 0.001]; % initial guess (x(1)=v, x(2)=f)
x = fsolve(@qdpfun,x0,[],dP,dz,rho,mu,L,D,rh);
v = x(1); f = x(2); Q = x(1)*pi*D^2/4; % volumetric flow rate
dPf = 2*f*rho*L*v^2/D; % pressure drop due to friction loss
fprintf('Volumetric flow rate of water = %g m^3/sec\n', Q);
fprintf('Pressure drop due to friction loss = %g kPa\n', dPf/1000);
function fun = qdpfun(x,dP,dz,rho,mu,L,D,rh)
v = x(1); f = x(2); g = 9.8; Nre = D*v*rho/mu; % Reynolds number
fun = [-v^2/2 + g*dz + dP/rho + 2*f*L*v^2/D; 1/sqrt(f) + 1.7372*log(rh/3.7/D + 1.255/Nre/sqrt(f))];
end
If you'll run the code, it shows, Unrecognized function or variable 'qdpfun'. Please help in solving the error in the code above

採用された回答

Davide Masiello
Davide Masiello 2022 年 5 月 2 日
Below, I show the right way to pass extra parameters to a function.
clear,clc
dP = -18*1.01325e5;
dz = 100;
rho = 1e3;
mu = 1e-3;
L = 1500;
D = 0.154;
rh = 4.57e-5;
x0 = [5 0.001];
x = fsolve(@(x)qdpfun(x,dP,dz,rho,mu,L,D,rh),x0);
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
v = x(1);
f = x(2);
Q = x(1)*pi*D^2/4; % volumetric flow rate
dPf = 2*f*rho*L*v^2/D; % pressure drop due to friction loss
fprintf('Volumetric flow rate of water = %g m^3/sec\n', Q);
Volumetric flow rate of water = 0.0610367 m^3/sec
fprintf('Pressure drop due to friction loss = %g kPa\n', dPf/1000);
Pressure drop due to friction loss = 849.219 kPa
function fun = qdpfun(x,dP,dz,rho,mu,L,D,rh)
v = x(1); f = x(2); g = 9.8; Nre = D*v*rho/mu; % Reynolds number
fun = [-v^2/2 + g*dz + dP/rho + 2*f*L*v^2/D; 1/sqrt(f) + 1.7372*log(rh/3.7/D + 1.255/Nre/sqrt(f))];
end
  3 件のコメント
Davide Masiello
Davide Masiello 2022 年 5 月 2 日
Have you copied the code in a script, saved it and then run it?
Crizel Joyz Amano
Crizel Joyz Amano 2022 年 5 月 2 日
tried it and it worked already. thank you so much for the help!!

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by