MATLAB: Strange behavior of dsolve

dsolveSymbolic Math Toolbox

The results of these blocks of instructions are both correct but different:
syms r s K P0 P(t)
simplify(dsolve(diff(P,t) == r*P*(1-P/K)-s*P, P(0) == P0))
>> (K*P0*exp(t*(r - s))*(r - s))/(K*r - K*s - P0*r + P0*r*exp(t*(r - s)))
syms r g K P0 P(t)
simplify(dsolve(diff(P,t) == r*P*(1-P/K)-g*P, P(0) == P0))
>> -(K*(g - r))/(r - (exp(t*(g - r))*(K*g - K*r + P0*r))/P0)
What's the matter with s and g???
My MATLAB version is 9.5.0.944444 (R2018b)

Best Answer

This workaround works in R2019a:
clear all
close all
clc
syms g r s K P0 P(t)
assume(g==s)
eq1 = simplify(dsolve(diff(P,t) == r*P*(1-P/K)-s*P, P(0) == P0))
eq2 = simplify(dsolve(diff(P,t) == r*P*(1-P/K)-g*P, P(0) == P0))
res = isequal(eq1,eq2)
Setting the assumption below the dsolve command will fail:
clear all
close all
clc
syms g r s K P0 P(t)
eq1 = simplify(dsolve(diff(P,t) == r*P*(1-P/K)-s*P, P(0) == P0))
eq2 = simplify(dsolve(diff(P,t) == r*P*(1-P/K)-g*P, P(0) == P0))
assume(g==s)
res = isequal(eq1,eq2)
Related Question