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