home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Mathematics / Notebooks / COSY_PAK / COSYPAK / chap3.m < prev    next >
Text File  |  1992-06-07  |  2KB  |  75 lines

  1.  
  2. (* 
  3. **********************************************************
  4.  
  5.          COSY_PAK package chap3.m        
  6.  
  7. **********************************************************
  8. *)
  9.  
  10.  
  11. If [ TrueQ[ $VersionNumber >= 2.0 ],
  12.      Off[ General::spell ];
  13.      Off[ General::spell1 ] ]
  14.      
  15. (*  B E G I N     P A C K A G E  *)
  16.  
  17.  
  18. BeginPackage["COSYPAK`chap3`",,"SignalProcessing`Support`SigProc`", 
  19.         "SignalProcessing`Analog`LaPlace`",
  20.         "SignalProcessing`Analog`InvLaPlace`"]         
  21.  
  22. Response::usage = "Response[ transf, Input, s, {TimeVar, StartTime, EndTime}, gopts]: Plots the output of transfer function `transf' with Laplace input signal `Input'.  The Laplace variable is `s'.  The output graph uses the variable `TimeVar' and starts at `StartTime' and ends at `EndTime'.  Returns the output variable as a function of time `t'.";
  23.  
  24. SecOrder::usage = "SecOrder[zeta, wn, t]: Gives the unit step response value at time instant t for a standard second order system wn2/(s2 + 2z wn s + wn2) with the damping ratio z=zeta and natural frequency wn =wn. Returns instantaneous value of the step response output variable at time instant `t'.";
  25.  
  26. Begin["`Private`"]
  27.  
  28. SecOrder/:SecOrder[damp_,wn_,t_]:=
  29.     Module[{wd},wd = wn Sqrt[1-damp^2]; 
  30.          1-E^(-damp wn t) (Cos[wd t]+damp/Sqrt[1-damp^2] Sin[wd t])]/;
  31.          0 <= damp < 1
  32.     
  33. SecOrder/:SecOrder[damp_,wn_,t_]:= 1 - E^(-wn t)( 1 + wn t)/;
  34.             Abs[damp - 1] < 0.0001
  35.             
  36. SecOrder/:SecOrder[damp_,wn_,t_]:=
  37.     Module[{s1,s2,temp}, temp = Sqrt[damp^2 -1];
  38.          s1 = (damp + temp) wn ;
  39.          s2 = (damp - temp) wn ;
  40.          y = 1 + wn/2/temp ( (E^(-s1 t))/s1 - (E^(-s2 t))/s2)
  41.          ]/;damp > 1
  42.  
  43. (*
  44.  
  45. *)    
  46. Response[transf_,input_,s_,{t_,tmin_,tmax_},opts___] :=
  47. Module[{outputlp ,output,inputfunc},
  48.     outputlp = transf input;
  49.     output = InvLaPlace[outputlp,s,t,Dialogue->False,Apart->All];
  50.     output = Simplify[ComplexExpand[output]];
  51.     inputfunc = InvLaPlace[input,s,t,Dialogue->False,Apart->All];
  52.     inputfunc = Simplify[ComplexExpand[inputfunc]];
  53.     
  54.     (* Apply SignalPlot to plot output in solid line and
  55.         inputfunc in dash line *)    
  56.     SignalPlot[output + inputfunc I,{t,tmin,tmax},
  57.         FrameLabel->{"Time","Y(t)","Time Response of G(s) "," "},
  58.         Frame->True,PlotRange -> All,GridLines->Automatic, 
  59.         FrameTicks -> {Automatic, Automatic,Automatic, Automatic},
  60.         opts];
  61.     Return[output]                    
  62.         
  63.         ]/; tmin < tmax
  64.  
  65.  
  66. End[];
  67. EndPackage[];
  68.  
  69. (*  E N D     P A C K A G E  *)
  70.  
  71. If [ TrueQ[ $VersionNumber >= 2.0 ],
  72.      On[ General::spell ];
  73.      On[ General::spell1 ] ]
  74.  
  75.