Message Boards Message Boards


Solving differential equation gives complex number

Posted 8 months ago
2 Replies
1 Total Likes

Differential Equation Modeling a Disease

I have been trying to sole the following IVP but get an answer with complex solutions although ALL the parameters are real.

eq = i'[t] + (\[Gamma] + \[Mu] - \[Lambda]) i[t] == -\[Lambda] i[t]^2

DSolve[{eq, i[0] == i0}, i[t], t]

How should I use the fact that all parameters are real as is i and t ? Thank you

2 Replies

The solution uses complex numbers, but its values are real and correct:

sol1 = DSolveValue[{eq, i[0] == i0}, i, t]
FullSimplify[{eq, i[0] == i0} /. i -> sol1]
Block[{\[Gamma] = 1, \[Mu] = 1, \[Lambda] = 1, i0 = 1}, 
 Plot[sol1[t], {t, 0, 1}]]

You can get an expression that uses only real objects this way:

sol = DSolveValue[eq, i, t]
param = Solve[sol[0] == i0, C[1], Reals]
mySol[t_] = 
  sol[t] /. param[[1]] /. ConditionalExpression -> (#1 &)]
Simplify[{eq, i[0] == i0} /. i -> mySol]

Dear Gianluca Giorni, Thank you so much.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract