Still the in the same example, I have:
s'(t)=r*s(t)-1/pi(0)*exp(r*t)
Solving this equation, we get:
s(t)= (C-t/pi(0))*exp(r*t)
This one, I can't figure out.
So we can write this as s'= rs- (1/pi(0))e^(rt)
That is a "linear, non-homogeneous, differential equation with constant coefficients". Since it is linear, we can separate out the "associated homogeneous equation", s'= rs, find the
general solution to it, then add on
any single solution to the entire equation.
s'= rs is easy to solve: write it as ds/dt= rs, then as ds/s= r dt and integerate: ln(s)= rt+ C so s= ce^(rt) where c= e^C.
Now, normally, since derivatives of e^(rt)
are of the form e^(rt), in order to get that "e^(rt)" on the right side of the original equation we would try something of the form s= Ae^(rt). But, here, e^(rt) is already a solution to the
homogeneous equation. Putting Ae^(rt) into the equation would just give us 0 no matter what A was. So, instead, try s= Ate^(rt). (Knowing that is mostly a matter of experience- just see what happens when we differentiate.) Then, using the product rule, s'= Ae^(rt)+ Arte^(rt)= Ae^(rt)(1+ rt). The equation becomes Ae^(rt)(1+ rt)= rAte^(rt)- (1/pi(0))e^(rt). e^(rt) is never 0 so we can divide by it: A(1+ rt)= A+ Art= rAt- 1/pi(0) so A= -1/pi(0). -(1/pi(0))te^(rt) is a solution to the entire equation.
So the general solution to the entire equation is s(t)= ce^(rt)- (1/pi(0))te^(rt)= e^(rt)(c- t/pi(0)).
A slightly different way to do it- called "variation of parameters": Knowing that ce^(rt), for any constant, c, is a solution to the associated homogeneous equation, we seek a solution to the entire equation of the form s= u(t)e^(rt). (That "c" in the original function is the "parameter" we are "varying" or replacing with a function of t.)
Now, using the product rule, s'= u'e^(rt)+ rue^(rt). The equation becomes u'e^(rt)+ rue^(rt)= rue^(rt)- (1/p(0))e^(rt). Precisely
because ce^(rt) satisfied the associated homogeneous equation, the "rue^(rt)" terms cancel, leaving u'e^(rt)= -(1/p(0))e^(rt). Again, we can divide by e^(rt) and are left with u'= -(1/p(0)) so that u(t)= -(1/p(0))t+ C. That means that our solution to the equation is s= u(t)e^(rt)= [-(1/p(0))t+ C]e^(rt)= Ce^(rt)- (1/p(0))te^(rt) again.