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

47 views (last 30 days)
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
Madipelli himani
Madipelli himani on 16 Apr 2022
iam getting this error Not enough input arguments.
Madipelli himani
Madipelli himani on 16 Apr 2022
unit_step
Not enough input arguments.
Error in unit_step (line 4)
len=length(t);

Sign in to comment.

Accepted Answer

Benjamin Kraus
Benjamin Kraus on 12 Feb 2016
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
Benjamin Kraus
Benjamin Kraus on 9 May 2016
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)

mukul chankaya
mukul chankaya on 8 Oct 2020
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

Chapat
Chapat on 11 Mar 2020
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

Chapat
Chapat on 11 Mar 2020
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!