求解Matlab中的微分方程-体外溶出度

问题描述 投票:0回答:1

我正在尝试解决与此问题类似的问题:Solving Differential Equations in Matlab

但是,这次不是将药物注射到皮下组织中并随后溶解,而是在更简单的情况下允许悬浮液溶解在900 ml的溶解浴中。

function dydt=odefcnNY_v12(t,y,D,Cs,rho,r0,N,V)
dydt=zeros(2,1);
dydt(1)=(-D*Cs)/(rho*r0^2)*(1-y(2))*y(1)/(1e-6+y(1)^2); % dr*/dt
dydt(2)=(D*4*pi*N*r0*(1-y(2))*y(1))/V; %dC*/dt
end

即上一个问题的吸收项被删除:

Absorption term: Af*y(2)

化合物也不同,因此MW,Cs和r0也不同,并且实验设置也不同,因此现在更改了W和V。为了允许这些更改,ode113调用更改为:

MW=336.43; % molecular weight
D=9.916e-5*(MW^-0.4569)*60/600000 %m2/s - [D(cm2/min)=9.916e-5*(MW^-0.4569)*60], divide by 600,000 to convert to m2/s 
rho=1300; %kg/m3
r0=9.75e-8; %m dv50
Cs=0.032; %kg/m3 
V=0.0009;%m3 900 mL dissolution bath
W=18e-6; %kg 18mg
N=W/((4/3)*pi*r0^3*rho); % particle number
tspan=[0 200*3600]; %s in 200 hours
y0=[1 0];
[t,y]=ode113(@(t,y) odefcnNY_v12(t,y,D,Cs,rho,r0,N,V), tspan, y0);
plot(t/3600,y(:,1),'-o') %plot time in hr, and r*
xlabel('time, hr')
ylabel('r*, (rp/r0)')
legend('DCU')
title ('r*');
plot(t/3600,y(:,1)*r0*1e6); %plot r in microns
xlabel('time, hr');
ylabel('r, microns');
legend('DCU');
title('r');
plot(t/3600,y(:,2),'-') %plot time in hr, and C*
xlabel('time, hr')
ylabel('C* (C/Cs)')
legend('DCU')
title('C*');

当前问题是此代码已运行3个小时,但仍未完成。现在与上面链接中的上一个问题有什么不同,就是要花这么长时间?

谢谢

enter image description here

matlab ode
1个回答
0
投票
我无法真正重现您的问题。我使用“标准” python模块numpy和scipy,复制了参数块,

MW=336.43; # molecular weight D=9.916e-5*(MW**-0.4569)*60/600000 #m2/s - [D(cm2/min)=9.916e-5*(MW^-0.4569)*60], divide by 600,000 to convert to m2/s rho=1300.; #kg/m3 r0=9.75e-8; #m dv50 Cs=0.032; #kg/m3 V=0.0009;#m3 900 mL dissolution bath W=18e-6; #kg 18mg N=W/((4./3)*pi*r0**3*rho); # particle number Af = 0; # bath is isolated

使用了与上一篇文章相同的ODE函数(记住Af=0

def odefcnNY(t,y,D,Cs,rho,r0,N,V,Af): r,C = y; drdt = (-D*Cs)/(rho*r0**2)*(1-C) * r/(1e-10+r**2); # dr*/dt dCdt = (D*4*pi*N*r0*(1-C)*r-(Af*C))/V; # dC*/dt return [ drdt, dCdt ];

并解决了ODE

tspan=[0, 1.0]; #1 sec #tspan=[0, 200*3600]; #s in 200 hours y0=[1.0, 0.0]; method="Radau" sol=solve_ivp(lambda t,y: odefcnNY(t,y,D,Cs,rho,r0,N,V,Af), tspan, y0, method=method, atol=1e-8, rtol=1e-11); t = sol.t; r,C = sol.y; print(sol.message) print("C*=",C[-1])

这很快完成,在第一秒中使用了235个步骤,在接下来的200小时中,使用了另外6个步骤来覆盖恒定的行为。

plots of the components

我只能通过将容差提高到不合理的大值(如1e-4),并且仅当用于化感的epsilon为1e-12时,才能弄乱它。然后,当半径达到零时的硬转弯太难了,步长控制器陷入循环。这更多是步长控制器粗略实现的错误,在Matlab例程中不应该这样。

© www.soinside.com 2019 - 2024. All rights reserved.