Unrecognized function or variable 'qdpfun"

1 vue (au cours des 30 derniers jours)
Crizel Joyz Amano
Crizel Joyz Amano le 1 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

Réponse acceptée

Davide Masiello
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);
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 commentaires
Davide Masiello
Davide Masiello le 2 Mai 2022
Have you copied the code in a script, saved it and then run it?
Crizel Joyz Amano
Crizel Joyz Amano le 2 Mai 2022
tried it and it worked already. thank you so much for the help!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Mobile Fundamentals dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by