% Define function names that I wish to solve
syms x(t) y(t);
k1 = 0.02;
k2 = 0.00004;
k3 = 0.0004;
k4 = 0.04;
ode1 = diff(x) == k1*x-k2*x*y;
ode2 = diff(y) == k3*x*y-k4*y;
odes = [ode1;ode2];
S = dsolve(odes);
I keep getting a warning when I'm trying to solve this very simple system of odes.

 Réponse acceptée

Star Strider
Star Strider le 3 Oct 2020
It is nonllinear because of the ‘x*y’ terms, so it does not have an analytic solution that the Symbolic Math Toolbox can solve for.
Likely the only way to solve it is to use odeToVectorField and matlabFunction functions to create an anonymous function to use with the numeric ODE solvers, such as ode45 or ode15s:
[VF,Sbs] = odeToVectorField(odes);
odsefcn = matlabFunction(VF, 'Vars',{T,Y});
.

6 commentaires

alright thanks!!
Star Strider
Star Strider le 3 Oct 2020
As always, my pleasurre!
David Bloom
David Bloom le 11 Déc 2023
Modifié(e) : Walter Roberson le 12 Déc 2023
Mind giving me a hand since you seem quite adept at this?
I'm currently trying to solve a 2nd order ODE with dsolve and getting a similar error despite knowing that a solution does exist. Do you think I will need to take a similar approach?
ODE:
Initial Conditions:
: Where
My code:
syms r(t) r0
Dr = diff(r);
D2r = diff(r,2);
ode = D2r + (1/t)*Dr - r + r^3 == 0;
rSol(t,r0) = dsolve(ode,[Dr(0)==0,r(10)==0,r(0)==r0])
Warning: Unable to find symbolic solution.
rSol(t, r0) = [ empty sym ]
This cannot work, for the same boundary condition reasons I recently happened to explain in https://www.mathworks.com/matlabcentral/answers/2058574-why-do-i-receive-the-error-while-running-the-code#answer_1368749
That said, MATLAB cannot handle it anyhow
syms r(t) r0
Dr = diff(r);
D2r = diff(r,2);
ode = D2r + (1/t)*Dr - r + r^3 == 0;
bc = [Dr(0)==0,r(10)==0,r(0)==r0];
rSol = dsolve(ode, bc)
Warning: Unable to find symbolic solution.
rSol = [ empty sym ]
rSol = dsolve(ode)
Warning: Unable to find symbolic solution.
rSol = [ empty sym ]
Maple and Mathematica cannot solve it either.
David Bloom
David Bloom le 12 Déc 2023
So how do I approach this problem then? In reality I have three initial conditions:
1)
2) positive value
3) which can be approximated as
I can live with choosing (2), but I'm not sure how to proceed with (1) and (3). Any thoughts?
David Bloom
David Bloom le 12 Déc 2023
Modifié(e) : David Bloom le 12 Déc 2023
I solved it myself and the issue comes down to the 1/r term. If you allow the interval to explicitly include r=0, then the symbolic solver fails to interpret it. However, if you change the interval from [0 20] to [1e-33 20] then it can indeed solve it.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by