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 CenterFile Exchange에서 Creating, 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