Demo #2
A Simple Calculation Using Mathematica

Having solved our simple differential equation describing investment growth by using analytical methods, lets now show how Mathematica can be used to solve it either analytically or numerically.

First, let's try the analytical approach:

DSolve[ {s'[t] == r s[t], s[0] == s0}, s[t],t]

which agrees with our previous result. 

Mathematica has very powerful graphics capabilities as well. To plot the solution for s0 = 1000 and r = 0.08:

s0 = 1000;
r = 0.08;
Plot[ s0 Exp[ r t],{t,0,40}]

You see that it is easy to construct a visual image of the solution to a differential equation. If the solution at a particular time is required:

s0 Exp[ r 40. ]

Finally, you can ask Mathematica to solve the differential equation numerically, rather than analytically. For most hard equations, this is typically the only way to make progress:

r = 0.08;
s0 = 1000;
NDSolve[{ s'[t] == r s[t], s[0]==s0}, s,{t,0,40}]

Notice that Mathematica has computed a numerical solution, i.e. a table of s values corresponding to a set of discrete times, and then fit an interpolating function to connect the points into a smooth curve.  If you want a specific value, say after 20 years:

s[20] /. %

Remember that the "%" stands for the last output (in this case the interpolating function) and the operator "/." serves to substitute that function for s[20]. 

If you want to plot the interpolating function, use the output on line 8, "%8", and the Evaluate[] function:

Plot[Evaluate[s[t] /. %8],{t,0,40}]

So you see the numerical solution plots up just like the analytical solution in this simple example!