function requires more input arguments to run

function [ dydt ]=a14(t,y)
mumax=0.5;
ks=1;
ki=3;
k=14;
i0=75;
a=0.014;
Yi=0.5;
kla=0.00095;
h=0.00316;
sgin=0.06;
%dydt=zeroes(size(y));
x=y(1);
sl=y(2);
sg=y(3);
i=i0/a*x*(1-exp(-a*x));
mu=mumax*sl/((sl+ks+sl^2/ki)*(i/i+k));
dydt(1)=mu*x;
dydt(2)=kla*((sg/h)-sl)- Yi*dydt(1);
dydt(3)=sgin-kla*((sg/h)-sl);
tspan=[0 9];
y0=[0.03 0 17];
[t,y]=ode45(@a14,tspan,y0);
subplot(2,2,1);
plot(t,y(:,2),'-',t,y(:,1),':',t,y(:,3));
legend('Sl','x','Sg','location','east','bold');
xlabel('time,d');
ylabel('conc.,g/L');
subplot(2,2,2);
plot(t,y(:,1),'-');
axis([0 10 0 1.2]);
xlabel('time,d');
ylabel('biomass,g/L');
subplot(2,2,3);
plot(t,y(:,2),'red');
axis([0 10 0 20]);
xlabel('time,d');
ylabel('Sl,g/L');
subplot(2,2,4);
plot(t,y(:,3),'-');
axis([0 10 0 20]);
xlabel('time,d');
ylabel('Sg,g/L');
tspan=[0 9];
y0=[0.03 0 17];
[t,y]=ode45(@a14,tspan,y0);
%hold off
end

 Accepted Answer

The call of ODE45 is inlcuded in the function to be integrated - twice. I guess, that you see the error message, when you click on the green triangle in the editor, which calls the function without input arguments.
The solution is to create a new file and separate the function to be integrated from the call of ODE45:
% Before the definition of the function!
tspan = [0 9];
y0 = [0.03 0 17];
[t,y] = ode45(@a14, tspan, y0);
plot(t, y);
function [ dydt ]=a14(t,y)
mumax=0.5;
ks=1;
ki=3;
k=14;
i0=75;
a=0.014;
Yi=0.5;
kla=0.00095;
h=0.00316;
sgin=0.06;
x = y(1);
sl = y(2);
sg = y(3);
i = i0/a*x*(1-exp(-a*x));
mu=mumax*sl/((sl+ks+sl^2/ki)*(i/i+k));
dydt = zeros(size(y)); % Required to reply a column vector
dydt(1) = mu*x;
dydt(2) = kla*((sg/h)-sl)- Yi*dydt(1);
dydt(3) = sgin-kla*((sg/h)-sl);
end

1 Comment

thank you this is my 1st matlab code. i used to code in c where while defining a function you can just use a variable and call it later while giving the variable a user inputed value.

Sign in to comment.

More Answers (1)

You forgot to show us the error! Here's another chance to read the posting guidelines:
Once you read that you'll learn you need to post ALL THE RED TEXT.
We have no idea what you passed in for t and y. For example, did you do this:
t = 10;
y = rand(5, 10);
[ dydt ]=a14(t,y)
Or did you not even define t and y and just clicked the green run triangle assuming MATLAB would somehow pick default values for t and y that would be acceptable for you? Because that won't happen.

6 Comments

This was the error message
Not enough input arguments.
Error in b14 (line 13)
x=y(1);
Yes, you did what I said, and suspected : you "just clicked the green run triangle assuming MATLAB would somehow pick default values for t and y"
You need to define something for t and y like Jan and I said.
i ran the code again after plotting the graphs before define the function but still got a couple of errors
% Before the definition of the function!
tspan=[0 9];
y0=[0.03 0 17];
[t,y]=ode45(@a14,tspan,y0);
subplot(2,2,1);
plot(t,y(:,2),'-',t,y(:,1),':',t,y(:,3));
legend('Sl','x','Sg','location','east');
xlabel('time,d');
ylabel('conc.,g/L');
subplot(2,2,2);
plot(t,y(:,1),'-');
axis([0 10 0 1.2]);
xlabel('time,d');
ylabel('biomass,g/L');
subplot(2,2,3);
plot(t,y(:,2),'red');
axis([0 10 0 20]);
xlabel('time,d');
ylabel('Sl,g/L');
subplot(2,2,4);
plot(t,y(:,3),'-');
axis([0 10 0 20]);
xlabel('time,d');
ylabel('Sg,g/L');
tspan=[0 9];
y0=[0.03 0 17];
[t,y]=ode45(@a14,tspan,y0);
function [ dydt ]=a14(t,y)
mumax=0.5;
ks=1;
ki=3;
k=14;
i0=75;
a=0.014;
Yi=0.5;
kla=0.00095;
h=0.00316;
sgin=0.06;
x = y(1);
sl = y(2);
sg = y(3);
i = i0/a*x*(1-exp(-a*x));
mu=mumax*sl/((sl+ks+sl^2/ki)*(i/i+k));
dydt = zeros(size(y)); % Required to reply a column vector
dydt(1) = mu*x;
dydt(2) = kla*((sg/h)-sl)- Yi*dydt(1);
dydt(3) = sgin-kla*((sg/h)-sl);
end
Error using legend (line 272)
Unknown property 'bold'
Error in pun (line 7)
legend('Sl','x','Sg','location','east','bold');
So, get rid of 'bold' in your call to legend.
thanks i did that and it worked perfectly without any errors but one of the plots is kind of unexpected.i tried reading up on how plot , subplot and axis functions work but couldn't quite get it.
%plotting biomass conc with time
subplot(2,2,2);
plot(t,y(:,1),'-');
axis([0 10 0 1.2]);
xlabel('time,d');
ylabel('biomass,g/L');
Expected Plot:
Plot i got from my code:
y(:, 1) has a max of 0.03208 but you're setting the upper limit for the y axis to be 1.2. Change it to something smaller:
axis([0 10 0 0.04]);

Sign in to comment.

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!