Symbolic ODEs aren't symbolic?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Joseph Monarres
am 20 Okt. 2021
Beantwortet: Star Strider
am 20 Okt. 2021
I am trying to solve a system of ODEs with initial conditions and graph them, but the solver isn't accepting my ODEs
Here is my code
clear
t_interval = [0, 1200];
k1 = 1.08e-3;
k2 = 1.19e-3;
k3 = 1.54e-3;
syms A(t) R(t) S(t)
ode1 = diff(A) == -k1*A;
ode2 = diff(R) == k1*A - k2*R - k3*R*S;
ode3 = diff(S) == k2*R + k3*R*S;
odes = [ode1, ode2, ode3];
initialA = A(0) == 0.019;
initialR = R(0) == 0;
initialS = S(0) == 0;
ICs = [initialA, initialR, initialS];
[Asol(t), Rsol(t), Ssol(t)] = dsolve(odes, ICs);
hold on
grid on
fplot(Asol,t_interval);
fplot(Rsol,t_interval);
plot(Ssol,t_interval);
Legend('A(t)','R(t)', 'S(t)');
However, I keep getting the above error message. Does this mean that an analytical solution doesn't exist? or am I doing something wrong in my equations?
After browsing this forum, I saw common problems that led to this error were not seperating variables and values with mathematical symbols or using undeclared symbols, but I don't think I have done any of that.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 20 Okt. 2021
Because of the ‘R*s’ terms, the system is nonlinear. The vast majority of nonlinear differential equations do not have analytic solutions.
Integrate it numerically. Use odeToVectorField to characterise it as a vector field, and matlabFunction to create an anonymous function from it that the numeric ODE solvers can work with.
k1 = 1.08e-3;
k2 = 1.19e-3;
k3 = 1.54e-3;
syms A(t) R(t) S(t) Y T
ode1 = diff(A) == -k1*A;
ode2 = diff(R) == k1*A - k2*R - k3*R*S;
ode3 = diff(S) == k2*R + k3*R*S;
odes = [ode1, ode2, ode3];
[VF,Subs] = odeToVectorField(odes)
odefcn = matlabFunction(VF, 'Vars',{T,Y})
t_interval = [0, 1200];
ic = [0, 0.019, 0];
[t,y] = ode45(odefcn, t_interval, ic);
figure
plot(t, y)
grid
legend(string(Subs))
Experiment to get different results.
.
0 Kommentare
Weitere Antworten (1)
Paul
am 20 Okt. 2021
I think the fundamental problem is that dsolve() can't find a solution. Then the error results because it doesn't know how to deal the LHS of the assignment in this case. Use the single variable form for the LHS and no error is shown
clear
t_interval = [0, 1200];
k1 = 1.08e-3;
k2 = 1.19e-3;
k3 = 1.54e-3;
syms A(t) R(t) S(t)
ode1 = diff(A) == -k1*A;
ode2 = diff(R) == k1*A - k2*R - k3*R*S;
ode3 = diff(S) == k2*R + k3*R*S;
odes = [ode1, ode2, ode3];
initialA = A(0) == 0.019;
initialR = R(0) == 0;
initialS = S(0) == 0;
ICs = [initialA, initialR, initialS];
% [Asol(t), Rsol(t), Ssol(t)] = dsolve(odes, ICs);
sol = dsolve(odes,ICs)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Equation Solving finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!