我需要使用matlab中的ode45函数帮助求解以下微分方程。
我的问题是关于等式的时间相关函数。
公式:
d(C(t)* W(t))/ dt = F1-F2
F1和F2是我想要传递给函数的常量。
以下是我现在正在使用的代码示例。为了使用欧拉方法解决ODE问题,但我想使用ODE45或适当的ODE求解器来比较结果。 Euler方法中的错误值可能导致错误信息。
T = 0.0125; %Duration (minutes)
dt = 0.01*T; %Time step duration (minutes)
nsteps = 15*T/dt; %Total number of timesteps
R = 0.01; %Resistance
P1 = 2; %Pressure 1
P2 = 5; %Pressure 2
P3 = 80; %Pressure 3
F1 = (P1-P2)/R; %Flow 1
F2 = (P2-P3)/R; %Flow 2
Cmin = 0.00003; %Min value of Cfunction
Cmax = 0.0146; %Max value of Cfunction
tplot = zeros(1,nsteps); %Allocate memory to save values.
P3plot = zeros(1,nsteps); %Allocate memory to save values.
%EULER'S Method.
for i=1:nsteps
t = i*dt;
Cnew = Cfunction(t+dt,Cmin,Cmax);
Cold = Cfunction(t,Cmin,Cmax);
P3 = ((F1-F2)*dt/Cnew)+((Cold*P3)/Cnew);
P3plot(i) = P3; %Save pressure values.
tplot(i) = t; %Save time values
end
plot(tplot,P3plot)
这是C:
的功能function CV=Cfunction(t,CVS,CVD)
T =0.0125; %Duration
TS=0.0050; %Duration
tcS=0.0025; %time constant
tcD=0.0075; %time constant
tc=rem(t,T); % tc=time in the current cycle,
if(tc<TS)
e=(1-exp(-tc/tcS))/(1-exp(-TS/tcS));
CV=CVD*(CVS/CVD)^e;
else
e=(1-exp(-(tc-TS)/tcD))/(1-exp(-(T-TS)/tcD));
CV=CVS*(CVD/CVS)^e;
end
提前致谢。
答案 0 :(得分:1)
看起来您的等式有一个简单的分析解决方案。假设所有参数都是double,Whandle是一个函数句柄,Whandle(t)是非零的,整合在[0,t]等上。
function y = C(t, Whandle, F1, F2)
y = 1/Whandle(t) * (F1 - F2) * t
end