3
$\begingroup$

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!!!

$\endgroup$
2
  • $\begingroup$ Did you read my answer before having accepted the Nasser's one? $\endgroup$
    – user64494
    Jan 30, 2019 at 18:44
  • $\begingroup$ It works fine if you add $Assumptions = t <100 before your DSolve. $\endgroup$
    – Bill Watts
    Jan 30, 2019 at 22:07

2 Answers 2

3
$\begingroup$

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[0] == 250;
sol = q[t] /. First@DSolve[ode, q[t], t]

Mathematica graphics

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[1]/. First@Solve[(sol/.t->0)==0,C[1]]

Mathematica graphics

(sol/.C[1]->myConstant)//Simplify

Mathematica graphics

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[0]==250;
sol=q[t]/.First@DSolve[{ode,q[101]==250},q[t],t]

Mathematica graphics

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.

$\endgroup$
2
  • $\begingroup$ Nasser, when I do the problem by hnad, I get the following: $\endgroup$
    – Ashish
    Jan 30, 2019 at 17:48
  • $\begingroup$ 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$. $\endgroup$
    – Ashish
    Jan 30, 2019 at 18:06
2
$\begingroup$

Another way is as follows.

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

{{Q[t] -> 1/2 (500 + 200 I b [Pi] - 5 t - 2 I b [Pi] t + 200 b Log[100] - 2 b t Log[100] - 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[100] - 
2 b t Log[100] - 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[10000] - 2 b Log[100 - t])

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.