Solving First order ODEs simultaneously

Hello, needed help figuring out why I cannot obtain a solution. I'm sure this is a solvable solution however I keep getting a warning saying no solution is found. Is there any mistake I'm making in the code?
Everything is a constant except E, Sr(t) & Er(t).
% Rigorous Solution Case #1
syms Sr(t) Er(t) E;
E = Ea - Er(t);
Unrecognized function or variable 'Ea'.
ode2a = diff(Sr(t),t) == -(k1*(Ea - Er(t))*Sr(t)) + krev1*Er(t);
ode3a = diff(Er,t) == (k1*(Ea - Er(t))*Sr(t)) - (krev1+k2)*Er(t);
odes = [ode2a; ode3a];
cond1 = Sr(0) == Sa;
cond2 = Er(0) == 0;
conds = [cond1; cond2];
[SrSol(t),ErSol(t)] = dsolve(odes,conds)

4 commentaires

Ea = 123; %just to have SOME value
k1 = 42; %just to have SOME value
k2 = 13; %just to have SOME value
krev1 = 48; %just to have SOME value
Sa = 5; %just to have SOME value
% Rigorous Solution Case #1
syms Sr(t) Er(t) E;
E = Ea - Er(t);
ode2a = diff(Sr(t),t) == -(k1*(Ea - Er(t))*Sr(t)) + krev1*Er(t);
ode3a = diff(Er,t) == (k1*(Ea - Er(t))*Sr(t)) - (krev1+k2)*Er(t);
odes = [ode2a; ode3a];
cond1 = Sr(0) == Sa;
cond2 = Er(0) == 0;
conds = [cond1; cond2];
sol = dsolve(odes,conds)
Warning: Unable to find symbolic solution.
sol = [ empty sym ]
sol2a = dsolve(ode2a)
sol2a = 
so3a = dsolve(ode3a)
so3a = 
I don't know that I would call those "solvable"
Valerie
Valerie le 28 Sep 2023
Is there a way to solve this mathematically?
Ea = 123; %just to have SOME value
k1 = 42; %just to have SOME value
k2 = 13; %just to have SOME value
krev1 = 48; %just to have SOME value
Sa = 5; %just to have SOME value
% Rigorous Solution Case #1
syms Sr(t) Er(t) E;
E = Ea - Er(t);
ode2a = diff(Sr(t),t) == -(k1*(Ea - Er(t))*Sr(t)) + krev1*Er(t);
ode3a = diff(Er,t) == (k1*(Ea - Er(t))*Sr(t)) - (krev1+k2)*Er(t);
eqns = [ode2a; ode3a];
cond1 = Sr(0) == Sa;
cond2 = Er(0) == 0;
conds = [cond1; cond2];
[eqs,vars] = reduceDifferentialOrder(eqns, [Sr(t), Er(t)])
eqs = 
vars = 
[M,F] = massMatrixForm(eqs,vars)
M = 
F = 
f = M\F
f = 
odefun = odeFunction(f,vars)
odefun = function_handle with value:
@(t,in2)[in2(2,:).*4.8e+1-in2(1,:).*5.166e+3+in2(2,:).*in2(1,:).*4.2e+1;in2(2,:).*-6.1e+1+in2(1,:).*5.166e+3-in2(2,:).*in2(1,:).*4.2e+1]
InitConditions = double(rhs(conds)) %watch out for order though!
InitConditions = 2×1
5 0
[T, Y] = ode45(odefun, [0 0.01], InitConditions);
subplot(2,1,1); plot(T, Y(:,1)); title(string(vars(1)))
subplot(2,1,2); plot(T, Y(:,2)); title(string(vars(2)))
%that almost looks like the initial conditions are reversed.
%what happens if we try reversing the conditions?
[Tr, Yr] = ode45(odefun, [0 0.01], flipud(InitConditions));
figure
subplot(2,1,1); plot(Tr, Yr(:,1)); title(string(vars(1)))
subplot(2,1,2); plot(Tr, Yr(:,2)); title(string(vars(2)))
Valerie
Valerie le 28 Sep 2023
Thank you so much!

Connectez-vous pour commenter.

 Réponse acceptée

Torsten
Torsten le 28 Sep 2023
Déplacé(e) : Torsten le 28 Sep 2023

1 vote

I'm quite sure there is no analytical solution for your system of ODEs since the right-hand sides are nonlinear in the unknown functions (term Er(t)*Sr(t)).

7 commentaires

Valerie
Valerie le 28 Sep 2023
Alright, thank you.
A numerical solution using one of the ODE integrators (e.g. ode15s) should be possible.
But you must give values to all the constants involved.
Ea = 123; %just to have SOME value
k1 = 42; %just to have SOME value
k2 = 13; %just to have SOME value
krev1 = 48; %just to have SOME value
Sa = 5; %just to have SOME value
fun = @(t,y)[-(k1*(Ea - y(2))*y(1)) + krev1*y(2);(k1*(Ea - y(2))*y(1)) - (krev1+k2)*y(2)];
y0 = [Sa;0];
tspan = [0 1];
[T,Y] = ode15s(fun,tspan,y0);
plot(T,Y)
Valerie
Valerie le 28 Sep 2023
Thanks so much! Is there a difference between the different ODE integrators?
Torsten
Torsten le 28 Sep 2023
The ode integrators are mainly classified as being suited to solve "nonstiff" (ode45) and "stiff" (ode15s) problems.
In your case with only two equations, I'd take a stiff integrator. It needs a little more memory, but is safe and efficient for both stiff and nonstiff problems.
Valerie
Valerie le 28 Sep 2023
Thank you so much for your patience! Very new to mathematica
Sam Chak
Sam Chak le 28 Sep 2023
Wolfram Mathematica uses DSolve. 😅
Valerie
Valerie le 29 Sep 2023
@Sam Chak I rage quit mathematica this week and is how I eneded up on MATLAB lol but thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by