(* Mathematica system homework example: This program 
   can be used to simulate the response of a first 
   order system towards most forcing function. *)

(* Load the Laplace package *)
   Needs["Calculus`LaplaceTransform`"]

(* USER - INPUT YOUR FORCING FUNCTION HERE! *)
   f[t_] := 0.5 Sin[5 t]

(* Laplace transform the forcing function *)
   fbar[s_] := LaplaceTransform[f[t],t,s]

(* Define the first order transfer function *)
   G1[s_] := gain/(tau s + 1)

(* Define the Laplace transform of the first order
   output in terms of the transfer function and input *)
   y1bar[s_] := G1[s] fbar[s]

(* Find the time domain solution *)
   y1[t_,gain_,tau_] = InverseLaplaceTransform[y1bar[s],s,t];

(* Define the first order response as a plot *)
   first[gain_,tau_] := Plot[y1[t,gain,tau]/gain, 
                             {t,0,10},AxesLabel -> {TIME,OUPUT}]

first[8,1]

(* We see from this example that the output of a first order system
   to a sine wave forcing function is also a sine wave, it takes about
   5 multiples of the time constant to reach the steady oscillation *)