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)

 Accepted Answer

Stephan
Stephan on 27 Mar 2019
Edited: Stephan on 27 Mar 2019
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)

More Answers (1)

I've just discovered the "reason": alphabetical order (with respect to r)!!!! Symbolic variables like w, z produce the same result as s; variables like a, q produce the same result as g.
Weird stuff.

Categories

Find more on Simulink in Help Center and File Exchange

Products

Release

R2018b

Tags

Community Treasure Hunt

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

Start Hunting!