Unrecognized function or variable 'qdpfun"
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Crizel Joyz Amano
le 1 Mai 2022
Commenté : Crizel Joyz Amano
le 2 Mai 2022
% 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
0 commentaires
Réponse acceptée
Davide Masiello
le 2 Mai 2022
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);
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
3 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Mobile Fundamentals dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!