Symbolically solve non-linear differential equation

I need to solve this equation symbolically because I need to use in integration
c1=0.047;
c2=0.053;
m1=0.0025;
m2=0.008;
l1=1/500;
l2=1/20;
b10=0.1;
b20=0.2;
syms t;
syms b2(t)
b1t=-(c1-m1)*b10/(((b10-1)*c1+m1)*exp(-(c1-m1)*t)-c1*b10);
eq2=diff(b2,t)==b2(t)*(c2*(1-b1t-b2(t))-m2-c1*b1t);
b2t=dsolve(eq2,b2(0)==b20);
num=eval(vpaintegral((l1*b1t+l2*b2t)*t*exp(-(l1*b1t+l2*b2t)*t),[0 10000]));
c, m and l are fixed paramters, b10 and b20 change for different setups of the simulation. When b10 is under 0.05 b2t can be computed in 10-15 seconds, but starting around b10=0.1 I cannot get it to work. I have let it run for over 40 minutes with no answer.
I know it has a solution because Maple can solve it in seconds, but all my code is in matlab and I cannot just change it now. I can't just copy it because the expresion is infernally long. Also I can evaluate it with ode45 with no problems, but then I don't have an expresion to integrate...
Does anyone know if there are any options to dsolve that I can use or maybe another speciallised package/function for these situations?
Thank you and have a good day.

 채택된 답변

Torsten
Torsten 2023년 6월 27일
편집: Torsten 2023년 6월 27일
You don't need to solve the equation symbolically.
Just solve simultaneously the two differential equations
%db2/dt=b2*(c2*(1-b1t-b2)-m2-c1*b1t) , b2(0) = b20
%dI/dt = (l1*b1t+l2*b2t)*t*exp(-(l1*b1t+l2*b2t)*t), I(0) = 0
by a numerical method (e.g. using ODE15S).
The value of I at t = 10000 gives you the integral value you are after.
c1=0.047;
c2=0.053;
m1=0.0025;
m2=0.008;
l1=1/500;
l2=1/20;
b10=0.2;
b20=0.2;
b1t=@(t)-(c1-m1)*b10/(((b10-1)*c1+m1)*exp(-(c1-m1)*t)-c1*b10);
fun = @(t,y)[y(1)*(c2*(1-b1t(t)-y(1))-m2-c1*b1t(t));(l1*b1t(t)+l2*y(1))*t*exp(-(l1*b1t(t)+l2*y(1))*t)];
tspan = [0 10000];
y0 = [b20;0];
[T,Y] = ode15s(fun,tspan,y0,odeset('RelTol',1e-12,'AbsTol',1e-12));
plot(T,Y(:,1))
Y(end,2)
ans = 542.0010

댓글 수: 3

Pedro
Pedro 2023년 6월 29일
편집: Pedro 2023년 6월 29일
Thanks!
I had no idea that could be done. I managed to make it run in the end by integrating with b1t as symbolic as well and using subs with the final expression. I will see which way runs faster, since I need to loop this calculation.
Pedro
I personally see no sense in making b1t symbolic apart from making your code slower, but maybe you have your reasons.
I was just traying things and it happened to help solving b2t, where my code was getting completely stuck.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

질문:

2023년 6월 27일

댓글:

2023년 6월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by