# Complex solutions to ODEs

How do I solve the following IVP problem in Mathematica so that I get real solutions?

$$Q'(t)=b - \dfrac{Q(t)}{100-t}; \quad Q(0)=250$$

I tried the following:

$$\text{\Assumptions}=b>0;\text{\Assumptions}=t>0;$$

$$f=\text{DSolve}\left[\left\{Q'(t)=b-\frac{Q(t)}{100-t},Q(0)=250\right\},Q,t\right][[1,1,2]]$$

$$f(t)$$

which results in the following:

$$\frac{1}{2} (-2 i \pi b t-2 b t \log (100)-200 b \log (t-100)+2 b t \log (t-100)+200 i \pi b+200 b \log (100)-5 t+500)$$

Any help would be much appreciated. Thanks!!!

• Did you read my answer before having accepted the Nasser's one? Jan 30, 2019 at 18:44
• It works fine if you add $Assumptions = t <100 before your DSolve. Jan 30, 2019 at 22:07 ## 2 Answers You can get complex solution, depending on your initial condition ! First solve without setting IC ode = q'[t] == b - q[t]/(100 - t); ic = q == 250; sol = q[t] /. First@DSolve[ode, q[t], t] The above is your solution q(t). It is all nice and no complex numbers. But you want the above to be 250 when t=0, so myConstant =C/. First@Solve[(sol/.t->0)==0,C] (sol/.C->myConstant)//Simplify So the complex solution comes from your initial conditions requirements at t=0. If you change initial conditions to something else, the solution is not complex. Push the time to over 100 ode=q'[t]==b- q[t]/(100-t); ic=q==250; sol=q[t]/.First@DSolve[{ode,q==250},q[t],t] And now the solution is real. So it depends on where you set the initial condition at and the complex solution comes from solving for constant of integration. • Nasser, when I do the problem by hnad, I get the following: Jan 30, 2019 at 17:48 • Nasser, when I do the problem by hand, I get the following:$-b(100-t)ln|100-t|+C(100-t)$which results in$C = 2.5+b ln100\$. Jan 30, 2019 at 18:06

Another way is as follows.

$$Assumptions = b > 0;$$Assumptions = t >= 0;
DSolve[{Q'[t] == b \[Minus] Q[t]/(100 \[Minus] t), Q == 250}, Q[t], t]


{{Q[t] -> 1/2 (500 + 200 I b [Pi] - 5 t - 2 I b [Pi] t + 200 b Log - 2 b t Log - 200 b Log[-100 + t] + 2 b t Log[-100 + t])}}

 FullSimplify[1/2 (500 + 200 I b \[Pi] - 5 t - 2 I b \[Pi] t + 200 b Log -
2 b t Log - 200 b Log[-100 + t] + 2 b t Log[-100 + t]),Assumptions->b > 0&& t> 0 && t <= 100]


-(1/2) (-100 + t) (5 + b Log - 2 b Log[100 - t])