Not enough input arguments

2 次查看(过去 30 天)
BG88
BG88 2018-9-26
I am new to Matlab and I am currently getting a problem that I do not have enough input arguments.
The code is as follows:
function P = Antoine(T,A,B,C) % vapour pressure [bar]
T = input('Temperature of water in degrees celcius = ')
T_k = 273.15 + T;
P = 10^(A - (B/(T_k + C))); % temperature [K]
if (0 < T) & (T <= 30)
A = 5.40221;
B = 1838.675;
C = -31.737;
end
if (30 < T) & (T <= 60)
A = 5.20389;
B = 1733.926;
C = -39.485;
end
if (60 < T) & (T <= 90)
A = 5.0768;
B = 1659.793;
C = -45.854;
end
end

回答(2 个)

madhan ravi
madhan ravi 2018-9-26
编辑:madhan ravi 2018-9-26
function P = Antoine(T,A,B,C) % vapour pressure [bar]
T = input('Temperature of water in degrees celcius = ')
T_k = 273.15 + T;
if (0 < T) & (T <= 30)
A = 5.40221;
B = 1838.675;
C = -31.737;
P = 10^(A - (B/(T_k + C))); % temperature [K]
elseif (30 < T) & (T <= 60)
A = 5.20389;
B = 1733.926;
C = -39.485;
P = 10^(A - (B/(T_k + C))); % temperature [K]
elseif (60 < T) & (T <= 90)
A = 5.0768;
B = 1659.793;
C = -45.854;
P = 10^(A - (B/(T_k + C))); % temperature [K]
end
end
  3 个评论
Walter Roberson
Walter Roberson 2018-9-26
The same formula is used for P each time in the code, so you might as well put the P calculation after the if tree.
However, be careful: if the use enters a non-positive T or a T > 90, then the code does not assign a value to P (or to the coefficients needed to calculate P)
madhan ravi
madhan ravi 2018-9-26
Thank you sir , the reason I put P in each tree is that I thought it might reduce the computational time.

请先登录,再进行评论。


Basil C.
Basil C. 2018-9-26
编辑:Basil C. 2018-9-26
The code you have written is correct all that you need to do is to define the variable P after you have defined the value of A,B,C,T (that is at the end of the if statements)
Also no need to use function P = Antoine(T,A,B,C) rather use function P = Antoine() as the arguments that are passed are not used to compute the value of P as they get overwritten
function P = Antoine() % vapour pressure [bar]
T = input('Temperature of water in degrees celcius = ');
T_k = 273.15 + T;
if (0 < T && T <= 30)
A = 5.40221;
B = 1838.675;
C = -31.737;
end
if (30 < T && T <= 60)
A = 5.20389;
B = 1733.926;
C = -39.485;
end
if (60 < T && T <= 90)
A = 5.0768;
B = 1659.793;
C = -45.854;
end
P = 10^(A - (B/(T_k + C))); % temperature [K]
end

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by