how to solve the error "Not enough input arguments."

how to solve the error "Not enough input arguments."
i have saved file as fick.m
function dydt = Fick(t,C,V,Ji,Je,J2i,J2e,tmax,Cinit)
dydt = (Ji(t,C)-Je(t,C)+J2i(t,C)-J2e(t,C))./V;
end
below file as practical.m
%%One Compartmental Model
clear all
clf % comment out if you want to use the increment tool
% set parameter values
V = 500; % litres water
Cin = 0.2; % mg chemical per litre water
Qi = 50; % litres of water per day
Qe = Qi; % equal volume flow rate
Cinit = 0; % no chemical in tank at time 0
tmax = 30; % time range over which to solve model (days)
% solve the differential equation
sol = ode45(@Fick,[0 tmax],Cinit,[],V,Ji,Je,J2i,J2e);
tstep = 0.01;
tspan = 0:tstep:tmax;
y = deval(sol,tspan);
plot(tspan,y)
xlabel('time (days)');
ylabel('Concentration (mg/l)');
*but i am getting following error..*
Error using Fick (line 2)
Not enough input arguments.

3 Comments

%unit step function
function [u]= unit_step (t) %Function definition
len=length(t);
for (i=1:1:len); %Conditional Loop
if (t(i)<0)
u(i)=0;
else
u(i)=1;
end
end
end
iam getting this error Not enough input arguments.
unit_step
Not enough input arguments.
Error in unit_step (line 4)
len=length(t);

Sign in to comment.

 Accepted Answer

When you pass a function handle to ode45, ode45 is only going to provide the first two input arguments (t and y). If you want to provide additional input arguments you need to use an anonymous function.
You can convert this line:
sol = ode45(@Fick,[0 tmax],Cinit,[],V,Ji,Je,J2i,J2e);
Into something like this:
CallFick = @(t,C) Fick(t,C,V,Ji,Je,J2i,J2e,tmax,Cinit);
sol = ode45(CallFick,[0 tmax],Cinit);
Note: I'm not completely sure 'C' is your dependent variable, or the usage of 'Cinit', so you may need to tweak this syntax a bit to get it to do what you want, but this is the general idea.
You can find more details on the Parameterizing Functions doc page under the heading "Parameterizing Using Anonymous Functions".

4 Comments

c and t are the inputs. still the same error persists.
thanks for answer.
The answer I provided was a general answer to the question of "how do I provide more inputs when passing a function handle to the ODE solver."
One thing that isn't clear is whether the variables Ji, Je, J2i, and J2e are functions or matrices. I don't see a definition for those variables anywhere, so they are either functions you created somewhere else, or they are variables that exist in your workspace. The way they are being used in your 'Fick' function looks like you are using them as functions, but they way you are passing them in as input arguments makes them look like variables. You cannot guarantee that 't' and 'y' (or 'C') will be integers, so you cannot use them as indices into a matrix. If you are trying to pass them as function handles, you need to append "@" to the beginning when providing them as input, but without knowing more information about Ji, Je, J2i, and J2e, that is just a guess.
If you provide a little more context (such as the ODE you are trying to solve) you may get more helpful answers.
i want to solve the equation attached in the file
I know a while has passed, but in case you haven't gotten this working yet, here is the basic code to solve that ODE.
First define a function to pass into the ODE solver. The first input is "t", but you don't need "t", so it will be ignored.
function dCdt = Fick(~,C,Qi,Ci,Qe,Jp,Jm,V)
dCdt = (Qi.*Ci-Qe.*C+Jp-Jm)./V;
end
Once you have the function, you can create a script like this:
Ci = 0.2;
C0 = 0;
Qi = 50;
Qe = Qi;
Jp = 1;
Jm = 1;
V = 500;
tMax = 30;
[t,C] = ode45(@(t,C) Fick(t,C,Qi,Ci,Qe,Jp,Jm,V), [0 tMax], C0);
plot(t,C)
Note: The function passed into the ODE solver is actually an anonymous function that takes just "t" and "C" as input and then calls Fick and provides the remaining inputs.

Sign in to comment.

More Answers (3)

Hi, good day everyone I am also getting "not enough input argument" While running
Function cost=optim_pi(k) Assignin ( 'base, 'k',k) ; sim('simulation model name') ; cost=ISE(length(ISE)) ; end ISE is integral square error to be optimization by GA Kindly reply
Hello! I am new in Matlab, I am having a problem in running this code with the function refraction_2layers (line 18) and line 25 The error message is not enough input arguments
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
Here is the program at line 18 and 25 I am having the not enough input arguments error

Community Treasure Hunt

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

Start Hunting!