MATLAB Answers

Not Enough Input Arguments

7,337 views (last 30 days)
TheLimpNinja
TheLimpNinja on 7 Nov 2012
Commented: Evan Curatolo on 27 Sep 2020 at 20:53
Hi, I'm very new to MATLAB and I am having some trouble. Lots of people have had the same problem but nobody seems to be able to explain or solve it in plain English. Could somebody please explain what this error is and how to fix it?
I have a simple function:
function [r]=Mec134function(w,theta_deg)
t2=10000;
theta_rad=(theta_deg./180).*pi;
t1=55090./(10*sin(theta_rad));
rx=(t1.*cos(theta_rad))-t2;
ry=w-(t1.*sin(theta_rad));
r=((rx).^2+(ry).^2).^0.5;
end
It seems to give this error for line 3 but I'm not sure why.
Thanks.

  9 Comments

Show 6 older comments
Walter Roberson
Walter Roberson on 26 Oct 2018
You need to pass a vector or 2D array as an argument to your PCA function. Or perhaps your m_img_train is somehow defined as a function.
krishnama raju
krishnama raju on 7 Oct 2019
sir in this code executing in matlab showing error in line 38.https://codeocean.com/capsule/7635653/tree/v1
Walter Roberson
Walter Roberson on 7 Oct 2019
Line 38 of which function?

Sign in to comment.

Accepted Answer

Akiva Gordon
Akiva Gordon on 8 Nov 2012
Edited: MathWorks Support Team on 27 Nov 2018
Your function defines 2 input arguments (w and theta_deg). When you run Mec134function, you must specify exactly two inputs, otherwise you will get the error "Not enough input arguments".
For example, if you run the Mec134function in the command window without specifying any arguments:
>> Mec134function
You get this error:
Not enough input arguments.
Error in Mec134function (line 3)
theta_rad=(theta_deg./180).*pi;
If you run the Mec134function and specify two input arguments, "w" and "theta_deg" (assuming "w" and "theta_deg" are defined), you do not get the error message:
>> Mec134function(w,theta_deg)
If you have the file "Mec134function.m" open in the Editor and you try to run the function by pressing the "Run" button or F5, MATLAB runs the Mec134function without any input arguments, and you get the error "Not enough input arguments". The "Run" button dropdown menu then opens prompting you to enter values for the missing input arguments.
Add the desired values and press enter. The values you enter are set as the default inputs when you click the "Run" button or F5 in the future.
To change the values, press the down arrow below the "Run" button and enter new values.

  5 Comments

Show 2 older comments
sayima mukhtar
sayima mukhtar on 3 Mar 2020
But after doing this it shows
Unrecognized function or variable 'X'.
Walter Roberson
Walter Roberson on 3 Mar 2020
Are you sure? I do not see any x or X variable in any code here until you scroll way down to
Evan Curatolo
Evan Curatolo on 27 Sep 2020 at 20:53
Oh man. Bless your soul. Thank you for this comment.

Sign in to comment.

More Answers (12)

TheLimpNinja
TheLimpNinja on 7 Nov 2012
Edited: Walter Roberson on 15 Jul 2016
sorry the function is
function [r]=Mec134function(w,theta_deg)
t2=10000;
theta_rad=(theta_deg./180).*pi;
t1=55090./(10*sin(theta_rad));
rx=(t1.*cos(theta_rad))-t2;
ry=w-(t1.*sin(theta_rad));
r=((rx).^2+(ry).^2).^0.5;
end
if that's clearer :-)

  3 Comments

Jonathan Epperl
Jonathan Epperl on 7 Nov 2012
This function needs 2 input arguments, w and theta_deg. If you type into the command window
Mec134function(2*pi, 120)
you should not be getting an error. If you do, please post your whole command and the whole error message.
David Barry
David Barry on 7 Nov 2012
Jonathan is correct, please ignore the other answer below.
As a complete aside, MATLAB has commands deg2rad and rad2deg.
Steven Lord
Steven Lord on 27 Dec 2016
Prior to release R2015b the deg2rad and rad2deg functions were part of Mapping Toolbox. In that release they moved into MATLAB.
As another solution that avoids converting between degrees and radians, MATLAB also has functions sind and cosd for computing the sine and cosine of angles in degrees and those have been part of MATLAB for quite some time. [I don't remember exactly when they were introduced.]

Sign in to comment.


TheLimpNinja
TheLimpNinja on 7 Nov 2012
Edited: Walter Roberson on 7 Nov 2012
Thanks :-)
will have a look at the "getting started"
I have a simple function:
function [r]=Mec134function(w,theta_deg)
t2=10000;
theta_rad=(theta_deg./180).*pi;
t1=55090./(10*sin(theta_rad));
rx=(t1.*cos(theta_rad))-t2;
ry=w-(t1.*sin(theta_rad));
r=((rx).^2+(ry).^2).^0.5;
end
that seems to give this error for line 2 but I'm not sure why.

  2 Comments

Jan
Jan on 30 Nov 2012
@TheLimpNinja: Please add all details, which describe the problem in the questions - you can edit it. The answers section is reserved for answers.
Waldemiro Kubucama
Waldemiro Kubucama on 1 Aug 2020
Hello, first press button "Run" in Matlab and after only you press the button "ENTER" i your computer. I think your problem will be solved.

Sign in to comment.


Brian Batson
Brian Batson on 29 Nov 2012
Edited: Brian Batson on 29 Nov 2012
I too am very new to Matlab, and tried to run the code above in .m (JP Donlon on Nov. 7th). However, I keep getting an error stating "Not enough input arguments." I'm not sure what this means, because I have attempted to run other code by professors which works on other computers. Is it something with my preference settings?
Also, when I run the Code Analyzer, there are no issues...not sure what is going on.

  4 Comments

Show 1 older comment
Image Analyst
Image Analyst on 30 Nov 2012
When you called Mec134function(), did you pass in two arguments, or did you even pass in any arguments at all? You didn't just write that code into Mec134function.m and click the green run button did you? Because it needs two arguments. Did you pass it two arguments? That's what it means when it says "Not enough input arguments" - that you didn't pass in enough input arguments.
Prerna Singh
Prerna Singh on 29 Mar 2020
Hi,
Could you please explain what do you mean by passing the arguments?
Thanks
prerna
Walter Roberson
Walter Roberson on 29 Mar 2020
https://www.mathworks.com/matlabcentral/answers/53100-not-enough-input-arguments#comment_109973

Sign in to comment.


Annie micheal
Annie micheal on 15 Jul 2016
Edited: Walter Roberson on 15 Jul 2016
How to rectify this error
Error using DetectFace (line 68)
Not enough input arguments.
the code is given below
I=imread('lena.jpg');
minFace = 20; % minimal size of the face that you are searching for
maxFace = 4000; % maximal size of the face that you are searching for
overlappingThreshold = 0.5; % overlapping threshold for grouping nearby detections
numThreads = 24; % number of cpu threads for parallel computing
if nargin > 2 && ~isempty(options)
if isfield(options, 'minFace') && ~isempty(options.minFace)
minFace = options.minFace;
end
if isfield(options, 'maxFace') && ~isempty(options.maxFace)
maxFace = options.maxFace;
end
if isfield(options, 'overlappingThreshold') && ~isempty(options.overlappingThreshold)
overlappingThreshold = options.overlappingThreshold;
end
if isfield(options, 'numThreads') && ~isempty(options.numThreads)
numThreads = options.numThreads;
end
end
%%test detector
if ~ismatrix(I)
I = rgb2gray(I);
end
candi_rects = NPDScan(model, I, minFace, maxFace, numThreads);
%%post processing
if isempty(candi_rects)
rects = [];
return;
end

  3 Comments

Walter Roberson
Walter Roberson on 15 Jul 2016
Please post the complete error message, everything in red.
The use of nargin, and the return near the end of the code, suggest strongly that you have posted part of the code for a function. We need to see the entire function, and we need to see what arguments you passed to the function.
NPDScan is not part of MATLAB. Are you getting it from https://github.com/biotrump/NPD/blob/master/NPDFaceDetector_Train/src/NPDScan.cpp ?
Annie micheal
Annie micheal on 15 Jul 2016
yeah i got it from NPDFaceDetector...
the entire code is
I=imread('lena.jpg');
minFace = 20; % minimal size of the face that you are searching for
maxFace = 4000; % maximal size of the face that you are searching for
overlappingThreshold = 0.5; % overlapping threshold for grouping nearby detections
numThreads = 24; % number of cpu threads for parallel computing
if nargin > 2 && ~isempty(options)
if isfield(options, 'minFace') && ~isempty(options.minFace)
minFace = options.minFace;
end
if isfield(options, 'maxFace') && ~isempty(options.maxFace)
maxFace = options.maxFace;
end
if isfield(options, 'overlappingThreshold') && ~isempty(options.overlappingThreshold)
overlappingThreshold = options.overlappingThreshold;
end
if isfield(options, 'numThreads') && ~isempty(options.numThreads)
numThreads = options.numThreads;
end
end
%%test detector
if ~ismatrix(I)
I = rgb2gray(I);
end
candi_rects = NPDScan(model, I, minFace, maxFace, numThreads);
%%post processing
if isempty(candi_rects)
rects = [];
return;
end
numCandidates = length(candi_rects);
predicate = eye(numCandidates); % i and j belong to the same group if predicate(i,j) = 1
% mark nearby detections
for i = 1 : numCandidates
for j = i + 1 : numCandidates
h = min(candi_rects(i).row + candi_rects(i).size, candi_rects(j).row + candi_rects(j).size) - max(candi_rects(i).row, candi_rects(j).row);
w = min(candi_rects(i).col + candi_rects(i).size, candi_rects(j).col + candi_rects(j).size) - max(candi_rects(i).col, candi_rects(j).col);
s = max(h,0) * max(w,0);
if s / (candi_rects(i).size^2 + candi_rects(j).size^2 - s) >= overlappingThreshold
predicate(i,j) = 1;
predicate(j,i) = 1;
end
end
end
% merge nearby detections
[label, numCandidates] = Partition(predicate);
rects = struct('row', zeros(numCandidates,1), 'col', zeros(numCandidates,1), ...
'size', zeros(numCandidates,1), 'score', zeros(numCandidates,1), ...
'neighbors', zeros(numCandidates,1));
for i = 1 : numCandidates
index = find(label == i);
weight = Logistic([candi_rects(index).score]');
rects(i).score = sum( weight );
rects(i).neighbors = length(index);
if sum(weight) == 0
weight = ones(length(weight), 1) / length(weight);
else
weight = weight / sum(weight);
end
rects(i).size = floor([candi_rects(index).size] * weight);
rects(i).col = floor(([candi_rects(index).col] + [candi_rects(index).size]/2) * weight - rects(i).size/2);
rects(i).row = floor(([candi_rects(index).row] + [candi_rects(index).size]/2) * weight - rects(i).size/2);
end
clear candi_rects;
% find embeded rectangles
predicate = false(numCandidates); % rect j contains rect i if predicate(i,j) = 1
for i = 1 : numCandidates
for j = i + 1 : numCandidates
h = min(rects(i).row + rects(i).size, rects(j).row + rects(j).size) - max(rects(i).row, rects(j).row);
w = min(rects(i).col + rects(i).size, rects(j).col + rects(j).size) - max(rects(i).col, rects(j).col);
s = max(h,0) * max(w,0);
if s / rects(i).size^2 >= overlappingThreshold || s / rects(j).size^2 >= overlappingThreshold
predicate(i,j) = true;
predicate(j,i) = true;
end
end
end
flag = true(numCandidates,1);
% merge embeded rectangles
for i = 1 : numCandidates
index = find(predicate(:,i));
if isempty(index)
continue;
end
s = max([rects(index).score]);
if s > rects(i).score
flag(i) = false;
end
end
rects = rects(flag);
% check borders
[height, width, ~] = size(I);
numFaces = length(rects);
for i = 1 : numFaces
if rects(i).row < 1
rects(i).row = 1;
end
if rects(i).col < 1
rects(i).col = 1;
end
rects(i).height = rects(i).size;
rects(i).width = rects(i).size;
if rects(i).row + rects(i).height - 1 > height
rects(i).height = height - rects(i).row + 1;
end
if rects(i).col + rects(i).width - 1 > width
rects(i).width = width - rects(i).col + 1;
end
end
end
function Y = Logistic(X)
Y = log(1 + exp(X));
Y(isinf(Y)) = X(isinf(Y));
end
Walter Roberson
Walter Roberson on 15 Jul 2016
Why did you use nargin and return when you wrote this script ? nargin is defined as being 0 within scripts and return can lead to odd behavior when used within a script .
When I search around, it looks to me as if this code is ripped off from https://github.com/biotrump/NPD/blob/master/NPDFaceDetector/DetectFace.m which is a function not a script . An example of calling that function is given in the comments there:
I = imread('lena.jpg');
load('model.mat');
rects = DetectFace(npdModel, I);
You cannot just remove the function line from a function and assign to one variable and expect it to work.

Sign in to comment.


REEMA MOHANTY
REEMA MOHANTY on 27 Dec 2016
Edited: Walter Roberson on 26 May 2017
clc; clear; close all;
xo=0.4;
A=[];
b=[];
Aeq=[];
beq=[];
Q=100;
R=1;
N = 50;
U0= zeros(100,1);
% Umin= -1*ones(100,1);
% Umax=1*ones(100,1);
% U = fmincon(@cost1,U0,A,b,Aeq,beq,Umin,Umax,[],[],N);
x=xo; h = 0.1;
xo=[-0.5,0.5];
options = optimoptions(@fmincon,'Algorithm','sqp');
U = fmincon(@cost1,U0,[],[],[],[],[],[],@confuneq,options);
for k =1:N
S1= F(x(k),U(k));
S2=F(x(k)+0.5*h*S1,U(k));
S3=F(x(k)+0.5*h*S2,U(k));
S4=F(x(k)+h*S3,U(k));
x(k+1) = x(k) + (1/6)* (S1+ 2*S2+ 2*S3 + S4)*h;
k = k + 1 ;
end
% plot(x);
plot(U);
grid on
figure(); plot(x)
grid on
I new to matlab.Can anyone help me to fix the iisue here.
Its showing not enough input arguments.

  0 Comments

Sign in to comment.


vani shree
vani shree on 3 Mar 2017
Edited: Walter Roberson on 3 Mar 2017
Hello sir,I am newer to matlab. I am getting error in this code like "preprocessing requries more input arugument to run". can you please to run this program. my project topic is recognition and matching fake logos using filters.
function img=preprocessing(I)
[x y o]=size(I);
if o==3
I=rgb2gray(I);
end
I=im2double(I);
%%MEDIAN FILTER
med=medfilt2(I);
figure,imshow(med)
title('MEDIAN FILTERED IMAGE')
[psnr_med,mse_med]=psnr(I,med)
%%AVERAGE FILTER
out7= imfilter(I, fspecial('average'));
figure,imshow(out7)
title('MEAN FILTERED IMAGE')
[psnr_avg,mse_avg]=psnr(I,out7)
%%GAUSSIAN FILTER
gau=imfilter(I,fspecial('gaussian'));
figure,imshow(gau)
title('GAUSSIAN FILTER IMAGE')
[psnr_gau,mse_avg]=psnr(I,gau)
%%WEINER FILTER
psf=fspecial('gaussian',7,10);
image1=imfilter(I,psf,'conv','circular');
var1=(1/256)^2/12;
var2=var(I(:));
wei=deconvwnr(image1,psf,(var1/var2));
figure,imshow(wei);title('WEINER FILTERED IMAGE');
[psnr_wei,mse_wei]=psnr(I,wei)
psnr_all=[psnr_med,psnr_avg,psnr_gau,psnr_wei];
psnr_max=max(psnr_all);
val=find(psnr_all==psnr_max);
if val==1
img=med;
disp('median have high psnr');
elseif val==2
img=out7;
disp('mean have high psnr');
elseif val==3
img=gau;
disp('gaussian have high psnr');
else
img=wei;
disp('weiner have high psnr');
end

  3 Comments

Walter Roberson
Walter Roberson on 3 Mar 2017
You cannot (typically) run functions just by clicking on the Run button. You have to go down to the command line and give the function name and indicate what parameters you are passing to it.
For example, at the command line you might do
MyImage = imread('cameraman.tif');
MyNewImage = preprocessing(MyImage);
This creates an image in the first line, and passes it to the preprocessing function in the second line, and assigns the result of preprocessing to the variable MyNewImage
vani shree
vani shree on 24 Mar 2017
thank you very much sir. and i have some other doubts regarding my project.my project title is recognition and detection of lake logos by context. i done 60% of coding like preprocessing and SIFT process but i dont know how to compare fake logo and original logo and the output should display which is fake logo. can u please help me to compare these two images.
Steven Lord
Steven Lord on 24 Mar 2017
vani shree, you should ask this as a separate question since it's not related to the "not enough input arguments" original question. Show what you've written and ask a specific question about where you're having difficulty and you may receive some guidance.

Sign in to comment.


Ganesh Petkar
Ganesh Petkar on 18 Apr 2017
I am getting error for below function as "Not enough input arguments. "
delayed_signal = mtapped_delay_fcn(input);

Wendell
Wendell on 26 May 2017
Edited: Walter Roberson on 26 May 2017
Hi I'm trying to run Dr. John Stockie's matlab code but I am getting a "Not enough input argument" error. I'm not very well verse with Matlab, so I would appreciate any help...Thank you. I am pasting the code:
function C = ermak( x, y, z, H, Q, U, Wset, Wdep )
% ERMAK: Compute contaminant concentration (kg/m^3) using the
% Gaussian plume model, modified for a deposition and settling
% velocity. This code handles a single source (located at the
% origin) and multiple receptors.
%
% Input parameters:
%
% x - receptor locations: distance along the wind direction, with
% the source at x=0 (m)
% y - receptor locations: cross-wind direction (m)
% z - receptor locations: vertical height (m)
% H - source height (m)
% Q - contaminant emission rate (kg/s)
% U - wind velocity (m/s)
% Wset - gravitational settling velocity (m/s)
% Wdep - deposition velocity (m/s)
%
% Output:
%
% C - contaminant concentration (kg/m^3)
%
% References: Ermak (1977), Winges (1990/1992).
% First, define the cut-off velocity, below which concentration = 0.
Umin = 0.0;
% Determine the sigma coefficients based on stability class C --
% slightly unstable (3-5 m/s).
ay = 0.34; by = 0.82; az = 0.275; bz = 0.82;
sigmay = ay*abs(x).^by .* (x > 0);
sigmaz = az*abs(x).^bz .* (x > 0);
% Calculate the eddy diffusivity (m^2/s).
Kz = 0.5*az*bz*U*abs(x).^(bz-1) .* (x > 0); % K = 0.5*U*d(sigma^2)/dx
% Calculate the contaminant concentration (kg/m^3) using Ermak's formula.
if U < Umin,
C = 0 * z;
else
Wo = Wdep - 0.5*Wset;
C = Q ./ (2*pi*U*sigmay.*sigmaz) .* exp( -0.5*y.^2./sigmay.^2 ) .* ...
exp( -0.5*Wset*(z-H)./Kz - Wset^2*sigmaz.^2/8./Kz.^2 ) .* ...
( exp( -0.5*(z-H).^2./sigmaz.^2 ) + ...
exp( -0.5*(z+H).^2./sigmaz.^2 ) - sqrt(2*pi)*Wo*sigmaz./Kz .* ...
exp( Wo*(z+H)./Kz + 0.5*Wo^2*sigmaz.^2./Kz.^2 ) .* ...
erfc( Wo*sigmaz/sqrt(2)./Kz + (z+H)./sqrt(2)./sigmaz ) );
ii = find(isnan(C) | isinf(C));
C(ii) = 0; % Set all NaN and inf values to zero.
end
and the error message refers to "sigmay" in line 31

  1 Comment

Walter Roberson
Walter Roberson on 26 May 2017
Please read the previous Answers here.

Sign in to comment.


aarthy reddy R
aarthy reddy R on 4 Sep 2019
Edited: Walter Roberson on 14 Oct 2019
function test(num1, num2,small,s)
load (small, num1, num2)
s = sum(num1, num2)
end
this the code for this i'm getting these errors
Not enough input arguments.
Error in test (line 3)
load (small, num1, num2)

  4 Comments

Show 1 older comment
aarthy reddy R
aarthy reddy R on 14 Oct 2019
load(filename, var1, var2)
so it is having 3 arguments
Walter Roberson
Walter Roberson on 14 Oct 2019
Okay, well you are trying to run test without passing in at least 3 input arguments. For example you might be trying to just press the green Run button, instead of going down to the command line and issuing a command in the command window.
Walter Roberson
Walter Roberson on 14 Oct 2019
Note: if you pass in the name of a variable as the fourth parameter, then the function you posted will not set that variable to the result of the sum. If you want to return a value in MATLAB you need to code it on the left side of an "=" in the function line. For example,
function s = test(num1, num2, small)
load (small, num1, num2)
s = sum(num1, num2)
end
This is unlikely to work the way you want it. In order for the load() to work there, small and num1 and num2 would each have to be a character vector or else a scalar string variable, and num1 and num2 would have to be in the same form as valid MATLAB variable names. Those names would have to be found inside the .mat file named by the small variable.
With the form of load() you have used, MATLAB would normally "poof" the variable names into existence. However, when you use end matching a function statement, you make a promise to MATLAB that you will not poof variables into existence, and MATLAB is permitted to give an error or to ignore the magically created variables. Therefore after the load, num1 and num2 are probably going to continue to be the character vectors or string objects, and you would attempt to call sum() passing those in. sum() would give an error if the first parameter, num1 is a string object, but would be okay with num1 being a character vector. There are a limited number of character vectors or scalar string objects that are valid for the second parameter of sum(), namely 'all', 'double', 'native', 'default', 'includenan', or 'omitnan' . It would be surprising if you happened to name your variables any of those...

Sign in to comment.


Chapat
Chapat on 11 Mar 2020
Edited: Walter Roberson on 11 Mar 2020
Hello. Am new in Matlab and I want to do my assignment with this function refraction_2layers and Matlab is saying error using refraction_2layers (line 18 and 25) Here is the whole program
function refraction_2layers(v1, v2, z, FIRST_ARRIVALS_ONLY);
% refraction_2layers(v1, v2, z);
%
% Creates travel time plots for a two-layers system with layer velocities
% v1 and v2 and layer 1 thickness of z
% The FIRST_ARRIVALS_ONLY FLAG may be set to 1 to plot only the first arrivals. By
% default, all arrivals are plotted.
if nargin < 4 FIRST_ARRIVALS_ONLY = 0; end
%% X-positions for geophones (m, relative to source)
x = [0:5:300];
%% Direct wave %% Travels along ground surface (at velocity v1)
t1 = x./v1;
%% Head wave
%% Refracts along z1-z2 boundary
%% Travel time depends on velocities of both layers
%% and thickness of layer 1 only (thickness of layer 2 irrelevant)
t2 = (2*z*sqrt(v2^2-v1^2)/(v1*v2))+x./v2; %% Note slope should be 1/v2!
xcrit = 2*z*v1/(sqrt(v2^2-v1^2));
if isreal(xcrit)
a = min(find(x>xcrit));
end
crossover = ((2*z*sqrt(v2^2-v1^2))/(v1*v2))/(1/v1-1/v2);
b = max(find(x<= crossover));
if FIRST_ARRIVALS_ONLY
plot(x(1:b),t1(1:b)*1000, '.--')
hold on
if isreal(t2)
plot(x(b:end), t2(b:end)*1000, 'r.--')
end
else
plot(x,t1*1000, '.--')
hold on
if isreal(t2)
plot(x(a:end), t2(a:end)*1000, 'r.--')
end
end
xlabel('GEOPHONE OFFSET (m)')
ylabel('TIME (ms)')
grid on
legend('DIRECT WAVE', 'HEAD WAVE')
title(['z1 = ', num2str(z), ' m; v1 = ', num2str(v1), ' m/s; v2 = ', num2str(v2), ' m/s'])
axis ([0 300 0 300])
hold off

  1 Comment

Walter Roberson
Walter Roberson on 11 Mar 2020
I formatted your code for you to make it readable to other people, but I suspect that I did not exactly preserve the line boundaries, so we do not know which lines are giving you the problem. Please mark them by using comments. Please also give the exact error messages.
Also please check the position of the end statements. It looked to me as if you might have had two extra end statements.

Sign in to comment.


Josilyn Dostal
Josilyn Dostal on 23 Apr 2020
I am really struggling to figure out this "not enough input arguments" error in my code. Any help would be greatly appreciated! This is for a batch distillation problem, and the error is referring to the temp function near the bottom. The code and error are below:
P = 912; % mmHg or 1.2 atm
L0 = 100; % Moles liquid in the still initially
A = [6.90565 6.95464]; B=[1211.033 1344.8]; C=[220.79 219.482]; % Antoine Constants
% x0 = [0.60 0.40]; % Initial liquid concentration xb = 60% xt = 40%
% xf = [0.20 0.80]; % Final liquid concentration xb = 20% xt = 80%
xtspan = linspace(0.40,0.80,100);
[xt, L] = ode45(@Moles, xtspan, L0);
L = L(end);
fprintf('The amount of liquid remaining in the still when liquid mole fraction of toluene reaches 0.80 is %f moles', L);
% Vapor liquid equilibrium ratio, K
function Kt = EquilibriumRatio(Psatt)
Kt = Psatt/P;
end
% Toluene vapor pressure
function Psatt = VaporPressuret(T,A,B,C)
Psatt = 10^(A(2)-B(2)/(T+C(2)));
end
% Benzene vapor pressure
function Psatb = VaporPressureb(T,A,B,C)
Psatb = 10^(A(1)-B(1)/(T+C(1)));
end
% ODE
function dLdx = Moles(xt,L)
T0 = 95.585;
%options = odeset('RelTol',1e-6,'AbsTol',1e-8);
%options = optimset('PlotFcns',{@optimplotx,@optimplotfval});
%options = optimset('Display','iter'); % show iterations
options = optimset('Display','off','TolX',1e-6); % Options
T = fzero(@temp, T0, options);
Psatt = VaporPressuret(T);
Kt = EquilibriumRatio(Psatt);
dLdx = L/(xt*(Kt-1));
end
function Tempfun = temp(T,xt,P,A,B,C)
Psatt = VaporPressuret(T,A,B,C);
Psatb = VaporPressureb(T,A,B,C);
Tempfun = Psatt*xt + Psatb*(1-xt) - P;
end
>> project2
Error using fzero (line 306)
FZERO cannot continue because user-supplied function_handle ==> temp failed with the error below.
Not enough input arguments.
Error in project2>Moles (line 30)
T = fzero(@temp, T0, options);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in project2 (line 7)
[xt, L] = ode45(@Moles, xtspan, L0);

  5 Comments

Show 2 older comments
Josilyn Dostal
Josilyn Dostal on 24 Apr 2020
Sorry to ask again, but i did what you said and am now getting a different error. The "not enough input arguments" error is gone, so that's great, thank you! Now the error has a problem with the "+" in my vapor pressure function, which makes no sense to me. Do you have any idea what this means? The code and error are below.
P = 912; % mmHg or 1.2 atm
L0 = 100; % Moles liquid in the still initially
% x0 = [0.60 0.40]; % Initial liquid concentration xb = 60% xt = 40%
% xf = [0.20 0.80]; % Final liquid concentration xb = 20% xt = 80%
xtspan = linspace(0.40,0.80,100);
[xt, L] = ode45(@Moles, xtspan, L0);
L = L(end);
fprintf('The amount of liquid remaining in the still when liquid mole fraction of toluene reaches 0.80 is %f moles', L);
% Vapor liquid equilibrium ratio, K
function Kt = EquilibriumRatio(Psatt)
Kt = Psatt/P;
end
% Toluene vapor pressure
function Psatt = VaporPressuret(T)
At = 6.95464;
Bt = 1344.8;
Ct = 219.482; % Antoine Constants
Psatt = 10^(At-(Bt/(T+Ct)));
end
% Benzene vapor pressure
function Psatb = VaporPressureb(T)
Ab = 6.90565;
Bb = 1211.033;
Cb = 220.79; % Antoine Constants
Psatb = 10^(Ab-(Bb/(T+Cb)));
end
% ODE
function dLdx = Moles(xt,L)
% fzero
function T = findzero(~)
T0 = 95.585;
T = fzero(@temp, T0);
% Temperature
function Tempfun = temp(T,xt,P)
Psatt = VaporPressuret(T);
Psatb = VaporPressureb(T);
Tempfun = Psatt*xt + Psatb*(1-xt) - P;
end
end
T = @findzero;
Psatt = VaporPressuret(T);
Kt = EquilibriumRatio(Psatt);
dLdx = L/(xt*(Kt-1));
end
Operator '+' is not supported for operands of type 'function_handle'.
Error in project5>VaporPressuret (line 19)
Psatt = 10^(At-(Bt/(T+Ct)));
Error in project5>Moles (line 45)
Psatt = VaporPressuret(T);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in project5 (line 6)
[xt, L] = ode45(@Moles, xtspan, L0);
Walter Roberson
Walter Roberson on 24 Apr 2020
P = 912; % mmHg or 1.2 atm
L0 = 100; % Moles liquid in the still initially
A = [6.90565 6.95464]; B=[1211.033 1344.8]; C=[220.79 219.482]; % Antoine Constants
% x0 = [0.60 0.40]; % Initial liquid concentration xb = 60% xt = 40%
% xf = [0.20 0.80]; % Final liquid concentration xb = 20% xt = 80%
xtspan = linspace(0.40,0.80,100);
[xt, L] = ode45(@(xt,L) Moles(xt,L,P,A,B,C), xtspan, L0);
L = L(end);
fprintf('The amount of liquid remaining in the still when liquid mole fraction of toluene reaches 0.80 is %f moles', L);
% ODE
function dLdx = Moles(xt, L, P, A, B, C)
T0 = 95.585;
%options = odeset('RelTol',1e-6,'AbsTol',1e-8);
%options = optimset('PlotFcns',{@optimplotx,@optimplotfval});
%options = optimset('Display','iter'); % show iterations
options = optimset('Display','off','TolX',1e-6); % Options
T = fzero(@(T)temp(T,xt,P,A,B,C), T0, options);
Psatt = VaporPressuret(T, A, B, C);
Kt = EquilibriumRatio(Psatt, P);
dLdx = L/(xt*(Kt-1));
end
function Tempfun = temp(T, xt, P, A, B, C)
Psatt = VaporPressuret(T, A, B, C);
Psatb = VaporPressureb(T, A, B, C);
Tempfun = Psatt*xt + Psatb*(1-xt) - P;
end
% Toluene vapor pressure
function Psatt = VaporPressuret(T, A, B, C)
Psatt = 10^(A(2)-B(2)/(T+C(2)));
end
% Vapor liquid equilibrium ratio, K
function Kt = EquilibriumRatio(Psatt, P)
Kt = Psatt/P;
end
% Benzene vapor pressure
function Psatb = VaporPressureb(T, A, B, C)
Psatb = 10^(A(1)-B(1)/(T+C(1)));
end
Josilyn Dostal
Josilyn Dostal on 24 Apr 2020
You are my savior. Youre so nice.

Sign in to comment.


Maria hassan
Maria hassan on 13 Jul 2020
Hi,
I am getting error 'Not enough input arguments.' I am trying online trail oversion. When I click run icon, it does not allow me to enter the value for the input as there is no option for entering the values. Any advice here please?
Best
Sarah

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!