function requires more input arguments to run

4 ビュー (過去 30 日間)
Sujay Bharadwaj
Sujay Bharadwaj 2021 年 11 月 7 日
コメント済み: Image Analyst 2021 年 11 月 8 日
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

採用された回答

Jan
Jan 2021 年 11 月 7 日
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 件のコメント
Sujay Bharadwaj
Sujay Bharadwaj 2021 年 11 月 7 日
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.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 11 月 7 日
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 件のコメント
Sujay Bharadwaj
Sujay Bharadwaj 2021 年 11 月 8 日
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:
Image Analyst
Image Analyst 2021 年 11 月 8 日
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]);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by