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.

 Respuesta aceptada

Torsten
Torsten el 27 de Jun. de 2023
Editada: Torsten el 27 de Jun. de 2023
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 comentarios

Pedro
Pedro el 29 de Jun. de 2023
Editada: Pedro el 29 de Jun. de 2023
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
Torsten
Torsten el 29 de Jun. de 2023
I personally see no sense in making b1t symbolic apart from making your code slower, but maybe you have your reasons.
Pedro
Pedro el 30 de Jun. de 2023
I was just traying things and it happened to help solving b2t, where my code was getting completely stuck.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 27 de Jun. de 2023

Comentada:

el 30 de Jun. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by