Search code examples
matlabsymbolic-mathdifferential-equationsdsolve

Matlab: dsolve with conditions not working


I'm trying to solve the system of differential equations given by variables eqn1 and eqn2.

lambda1 = 3;
lambda2 = 2;
gamma1 = 1;
gamma2 = 1;
delta1 = 1;
delta2 = 1;

syms n1(t) n2(t)
eqn1 = diff(n1) == (lambda1 - gamma1)*n1 - delta1*(n1 + n2)*n1;
eqn2 = diff(n2) == (lambda2 - gamma2)*n2 - delta1*(n1 + n2)*n2;

c1 = n1(0) == 10;
c2 = n2(0) == 10;
[a, b] = dsolve(eqn1, eqn2, c1, c2)

If I don't specify the conditions c1 and c2 and run just:

[a, b] = dsolve(eqn1, eqn2)

then everything is fine and I get:

a =

(6*exp(2*t)*n1(0))/(3*exp(2*t)*n1(0) + 4*exp((3*t)/2)*n2(0) + 6)


b =

(6*exp(t/2)*exp(t)*n2(0))/(3*exp(2*t)*n1(0) + 4*exp((3*t)/2)*n2(0) + 6)

but as soon as I try to specify n1(0) and n2(0), as you can see in the source code, I get the following warning:

a =

Warning: The result cannot be displayed due a previously interrupted     computation or out of memory. Run 'reset(symengine)' and rerun the commands to regenerate the result. 
> In sym.disp at 36
  In sym.display at 37
  In competingForResources at 15 

b =

     []

And I'm unable to plot the result. What am I missing there? How to specify the conditions the right way, so I get a plottable result?


Solution

  • You can directly substitute the values in the result using subs

    [a, b] = dsolve(eqn1, eqn2);
    a=subs(a,'n1(0)',10);
    a=subs(a,'n2(0)',10)
    
    a =
    
    (60*exp(2*t))/(30*exp(2*t) + 40*exp((3*t)/2) + 6)
    

    Same with b