home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 41 / IOPROG_41.ISO / soft / c++ / NUMCPP11.ZIP / residual.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-17  |  2.0 KB  |  77 lines

  1. //===================================================================
  2. // residual.h
  3. //
  4. // Version 1.1
  5. //
  6. // Written by:
  7. //   Brent Worden
  8. //   WordenWare
  9. //   email:  Brent@Worden.org
  10. //
  11. // Copyright (c) 1998-1999 WordenWare
  12. //
  13. // Created:  August 28, 1998
  14. // Revised:  April 10, 1999
  15. //===================================================================
  16.  
  17. #ifndef _RESIDUAL_HPP_
  18. #define _RESIDUAL_HPP_
  19.  
  20. #include "numerics.h"
  21.  
  22. NUM_BEGIN
  23.  
  24. template<class Iter, class Value>
  25. void resid(Iter first, Iter last, Value val)
  26. //-------------------------------------------------------------------
  27. // Replaces the elements in [first, last) with thier deviations from
  28. // val.
  29. //-------------------------------------------------------------------
  30. {
  31.     while(first != last){
  32.         *first -= val;
  33.         ++first;
  34.     }
  35. };
  36.  
  37. template<class Iter, class Value>
  38. void aresid(Iter first, Iter last, Value val)
  39. //-------------------------------------------------------------------
  40. // Replaces the elements in [first, last) with thier absolute
  41. // deviations from val.
  42. //-------------------------------------------------------------------
  43. {
  44.     while(first != last){
  45.         *first = absoluteValue(*first - val);
  46.         ++first;
  47.     }
  48. };
  49.  
  50. template<class Iter, class Value>
  51. void nresid(Iter first, Iter last, Value val, double n)
  52. //-------------------------------------------------------------------
  53. // Replaces the elements in [first, last) with thier deviations from
  54. // val raised to the n-th power.
  55. //-------------------------------------------------------------------
  56. {
  57.     if(n != 1.0){
  58.         while(first != last){
  59.             *first = pow(*first - val, n);
  60.             ++first;
  61.         }
  62.     } else {
  63.         resid(first, last, val);
  64.     }
  65. };
  66.  
  67. NUM_END
  68.  
  69. #endif
  70.  
  71. //===================================================================
  72. // Revision History
  73. //
  74. // Version 1.0 - 08/28/1998 - New.
  75. // Version 1.1 - 04/10/1999 - Added Numerics namespace.
  76. //===================================================================
  77.