# Why am I receiving Not enough input arguments?

5 views (last 30 days)
Andrew Hannah on 21 Sep 2022
Commented: Andrew Hannah on 22 Sep 2022
hello, I am working on an assignment where I need to find the pressure difference for 9 different states. Everything goes fine until i reach the turbulent flow section, where I can not figure out what to do. Any help would be appreciated. I have posted the three codes and the error towards the bottom
% P1 driver
clear
clc
p = 680;
u = 2.92*10^-4;
d = .01;
L = 2;
M = zeros(3,3);
% V1 E1
e = 0;
V = 0.05;
[f,flow, P] = fandp(V, d, L, e, p, u);
P1 = P;
M(1,1) = P1;
% V1 E2
e = 0.00015;
V = 0.05;
[f,flow, P] = fandp(V, d, L, e, p, u);
P2 = P;
M(1,2) = P2;
% V1 E3
e = 0.002;
V = 0.05;
[f,flow, P] = fandp(V, d, L, e, p, u);
P3 = P;
M(1,3) = P3;
% V2 E1
e = 0;
V = 0.1;
[f,flow, P] = fandp(V, d, L, e, p, u);
M(2,1) = P;
% V2 E2
e = 0.00015;
V = 0.1;
[f,flow, P] = fandp(V, d, L, e, p, u);
M(2,2) = P;
% V2 E3
e = 0.002;
V = 0.1;
[f,flow, P] = fandp(V, d, L, e, p, u);
M(2,3) = P;
% V3 E1
e = 0;
V = 0.5;
[f,flow, P] = fandp(V, d, L, e, p, u);
M(3,1) = P;
% V3 E2
e = 0.00015;
V = 0.5;
[f,flow, P] = fandp(V, d, L, e, p, u);
M(3,2) = P;
% V3 E3
e = 0.002;
V = 0.5;
[f,flow, P] = fandp(V, d, L, e, p, u);
M(3,3) = P;
here is the called function fandp:
function [f,flow, P] = fandp(V, d, L, e, p, u)
%flow_type Determines if flow is laminar, in transition, or turbulent
% V = velocity (m/s)
% d = diameter of pipe (m)
% L = length of pipe (m)
% e = roughness of pipe (m)
% p = density of fluid (kg/m^3)
% u = dynamic viscosity of fluid (Pa*s)
% flow = laminar, transition, or turbulent
% pressure = pressure difference required for desired flow
Re = 0;
P = 0;
%setup variables
xMin= -0.3;
xMax= 0.3;
tol=10^-8;
% gravity
g = 9.81;
%Calculate Reynolds Number
Re = (p*V*d)/u;
%Determine Flow Type
if Re < 2000
flow = 'laminar';
elseif Re > 3000
flow = 'turbulent';
elseif Re > 2000 && Re < 3000
flow = 'transition';
end
% f
if strcmp(flow, 'laminar')
f = (64/Re);
elseif strcmp(flow, 'turbulent')
[x_r] = bisect(@func,xMin,xMax,tol);
f = x_r;
elseif strcmp(flow, 'transition')
f = NaN;
end
check = isnan(f);
if check == 1
P = NaN;
else
% h
h = f*(L/d)*((V^2)/(2*g));
% P
P = p*g*h;
end
end
% Testing Function
function [f]=func(x,e,d,p,V,u)
f = -2*log((e/d)/3.7+(2.51/(p*V*d/u)*x^(1/2)))-(1/x^(1/2));
end
and here is the bisection function:
function [x_r,err,iter] = bisect(func,xMin,xMax,tol)
%This program will use the bisection method to find the roots to
%a function
%INPUTS:
%func is the function you want to find roots to
%xMin is the low range to begin the search
%xMax is the high value to search within
%tol is the acceptable error. The smaller the tol, the more
%iterations required. Recommended value is 1e-8
%OUTPUTS:
%x_r is the root to func
%err is the relative error of x_r, as measured by X-tol
a=func(xMin);
b=func(xMax);
if a*b>0
disp('Error: ends must evaluate to opposite signs');
return
end
iter=0;
x_Last=xMin;
err=abs(xMax-xMin);
iters = [];
roots = [];
errs =[];
while err>tol && iter<50
iter=iter+1;
iters = [iters,iter];
x_r =(xMax+xMin)/2;
c=func(x_r);
if a*c>0
xMin=x_r;
a=c;
elseif a*c<0
xMax=x_r;
b=c;
else
return;
end
if abs(x_r)>1
err=abs((x_r-x_Last)/x_r);
else
err=abs(x_r-x_Last);
end
x_Last=x_r;
roots =[roots,x_r];
errs =[errs,err];
end
%this renames the arrays to the name they are supposed
%to be according to the Lab03 .docx
x_r = roots;
err = errs;
iter = iters;
end
here is the error i am getting:
Not enough input arguments.
Error in fandp>func (line 61)
f = -2*log((e/d)/3.7+(2.51/(p*V*d/u)*x^(1/2)))-(1/x^(1/2));
Error in bisect (line 13)
a=func(xMin);
Error in fandp (line 40)
[x_r] = bisect(@func,xMin,xMax,tol);
Error in P1driver (line 56)
[f,flow, P] = fandp(V, d, L, e, p, u);
Can someone please tell me where I went wrong?

James Tursa on 21 Sep 2022
Edited: James Tursa on 21 Sep 2022
The error seems pretty clear, you are calling func( ) without enough input arguments. The func( ) signature has six inputs:
function [f]=func(x,e,d,p,V,u)
and here you are calling it with less than six inputs:
a=func(xMin);
b=func(xMax);
:
c=func(x_r);
@(x)func(x,e,d,p,V,u)
Andrew Hannah on 22 Sep 2022
Thank you! I got it working based on your suggestion.

Matt Butts on 21 Sep 2022
I am pretty sure this is because you have defined func as having 6 inputs, but when you call it from within bisect you are only passing one input.

### Categories

Find more on Fluid Dynamics in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by