ODE45功能矩阵维度问题

2 views (last 30 days)
Carey n'eville
Carey n'eville on 8 Jan 2021
编辑: Star Strider on 8 Jan 2021
Hello friends I wrote a code. But this does not work. In this problem I have a parameter with range. I could not figure out how can I write. I tried something but it didn't work. I need to observe different Y_H values effects on system.
Parameter with range:
y_h = [0.6 0.7]
代码
清除 全部 ;
clc;
close 全部 ;
global mu_H Y_H Ks X_BH teta Ss_in
mu_Hmax=0.15; %days^-1
T=22.6; %centigrade
X_BH=2295; %mg/l
teta=1.25; %day
y_h = [0.6 0.7];
KS = 250; %mg/l
%initial condition is Ss_in=1127 mg/l
Ss_in=1127; %mg/l
mu_h = mu_hmax*1.072^(t-20); %day^-1
tspan=[30 32 34 36 50 52 57 59 61 63 65 72 75 76 79 83 85 87 89 96 99 106 109 116 118 121 124 125 126 127 131 133 134 135 136 137 140];
ODE45(@substrate,tspan,Ss_in)
plot(t,Ss);
xlabel( 'Time (day)' )
ylabel( 'Concentrations (mg/L)' )
legend ( 'Substrate' )
function Derivative = substrate (t,Ss)
global mu_H Y_H Ks X_BH teta Ss_in
Derivative = -((mu_H/Y_H)*(Ss/(Ks+Ss))*X_BH)+((1/teta)*(Ss_in-Ss)); %DSS/DT
衍生物=衍生物(:);
end
ERRORS I HAVE
Error using /
Matrix dimensions must agree.
Error in Solutionofmodeleqn31>substrate (line 26)
Derivative = -((mu_H/Y_H)*(Ss/(Ks+Ss))*X_BH)+((1/teta)*(Ss_in-Ss)); %dSs/dt
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args {:});%ode15i设置args {1}到yp0。
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Solutionofmodeleqn31 (line 18)
ODE45(@substrate,tspan,Ss_in)

答案(2)

Alan Stevens
Alan Stevens on 8 Jan 2021
你需要遍历Y_H值。看到below
globalmu_H Ks X_BH teta Ss_in
mu_Hmax=0.15;%days^-1
T=22.6;%centigrade
X_BH=2295;%mg/l
teta=1.25;%day
y_h = [0.6 0.7];
KS = 250;%mg/l
%initial condition is Ss_in=1127 mg/l
Ss_in=1127;%mg/l
mu_h = mu_hmax*1.072^(t-20);%day^-1
tspan=[30 32 34 36 50 52 57 59 61 63 65 72 75 76 79 83 85 87 89 96 99...
106 109 116 118 121 124 125 126 127 131 133 134 135 136 137 140];
Ss = zeros(numel(t),numel(Y_H));
% Loop through Y_H values
fori = 1:numel(Y_H)
[t,Ss(:,i)] =ode45(@(t,Ss) substrate(t,Ss,Y_H(i)),tspan,Ss_in);
end
plot(t,Ss);
xlabel('Time (day)')
ylabel('Concentrations (mg/L)')
legend ('Substrate')
functionDerivative = substrate (~,Ss,Y_H)
globalmu_H Ks X_BH teta Ss_in
Derivative = -((mu_H/Y_H)*(Ss/(Ks+Ss))*X_BH)+((1/teta)*(Ss_in-Ss));%DSS/DT
衍生物=衍生物(:);
end

Star Strider
Star Strider on 8 Jan 2021
编辑:Star Strider on 8 Jan 2021
Do not use global variables!
Pass the additional parameters as arguments to the function, and use an appropriate anonymous function call in ODE45 .
Try this:
mu_Hmax=0.15;%days^-1
T=22.6;%centigrade
X_BH=2295;%mg/l
teta=1.25;%day
y_h = [0.6 0.7];
KS = 250;%mg/l
%initial condition is Ss_in=1127 mg/l
Ss_in=1127;%mg/l
mu_h = mu_hmax*1.072^(t-20);%day^-1
tspan=[30 32 34 36 50 52 57 59 61 63 65 72 75 76 79 83 85 87 89 96 99 106 109 116 118 121 124 125 126 127 131 133 134 135 136 137 140];
fork = 1:numel(y_h)
[TV,SSV(:,K)] = ODE45(@(t,ss)底物(t,ss,mu_h,y_h(k),ks,ks,x_bh,teta,ss_in,ss_in),tspan,ss_in);
end
figure
plot(tv,Ssv);
xlabel('Time (day)')
ylabel('Concentrations (mg/L)')
grid
legend (compose('基板:y_h =%.1f',y_h))
function衍生物=底物(T,SS,U_H,Y_H,KS,X_BH,TETA,SS_IN)
Derivative = -((mu_H/Y_H)*(Ss/(Ks+Ss))*X_BH)+((1/teta)*(Ss_in-Ss));%DSS/DT
衍生物=衍生物(:);
end
EDIT — (2021年1月8日,16:08)
Corrected typographical error.

下载188bet金宝搏


发布

R2020b

Community Treasure Hunt

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

开始狩猎!