home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 2-8.C < prev    next >
C/C++ Source or Header  |  1991-12-04  |  902b  |  30 lines

  1. /* Copyright (c) 1992 by AT&T Bell Laboratories. */
  2. /* Advanced C++ Programming Styles and Idioms */
  3. /* James O. Coplien */
  4. /* All rights reserved. */
  5.  
  6. #include <complex.h>
  7.  
  8. typedef double time;
  9.  
  10. class SeriesRLCStepResponse {
  11. public:
  12.     complex (SeriesRLCStepResponse::*current)(time t);
  13.     SeriesRLCStepResponse(double r, double l,
  14.         double c, double initialCurrent);
  15.     double frequency() const { return 1.0 / sqrt(L * C); }
  16. private:
  17.     complex underDampedResponse(time t) {
  18.         return exp(-alpha * t) * (b1 * cos(omegad * t) +
  19.                b2 * sin(omegad * t));
  20.     }
  21.     complex overDampedResponse(time t) {
  22.         return a1 * exp(s1 * t) + a2 * exp(s2 * t);
  23.     }
  24.     complex criticallyDampedResponse(time t) {
  25.         return exp(-alpha * t) * (a1 * t + a2);
  26.     }
  27.     double R, L, C, currentT0, alpha;
  28.     complex omegad, a1, b1, a2, b2, s1, s2;
  29. };
  30.