Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Quadratic.cxx

Go to the documentation of this file.
00001 /*
00002  * HippoPlot Quadratic class implementation
00003  *
00004  * Copyright (C) 2000, 2003   The Board of Trustees of The Leland
00005  * Stanford Junior University.  All Rights Reserved.
00006  *
00007  * $Id: Quadratic.cxx,v 1.37 2003/02/23 19:16:44 pfkeb Exp $
00008  *
00009  */
00010 
00011 #ifdef HAVE_CONFIG_H
00012 #include "config.h"
00013 #else
00014 #ifdef _MSC_VER
00015 #include "msdevstudio/MSconfig.h"
00016 #endif
00017 #endif
00018 
00019 #include "Quadratic.h"
00020 
00021 #include "FunctionHelper.h"
00022 
00023 #include <cassert>
00024 
00025 #ifdef ITERATOR_MEMBER_DEFECT
00026 using namespace std;
00027 #else
00028 using std::vector;
00029 #endif
00030 
00031 Quadratic::Quadratic ( )
00032 {
00033   initialize ();
00034 }
00035 
00036 Quadratic::Quadratic ( double intercept, double linear, double quad )
00037 {
00038   initialize ();
00039 
00040   m_parms[0] = intercept;
00041   m_parms[1] = linear;
00042   m_parms[2] = quad;
00043 }
00044 
00045 void Quadratic::initialize ()
00046 {
00047   m_name = "Quadratic";
00048 
00049   m_parm_names.push_back ( "Intercept" );
00050   m_parm_names.push_back ( "Linear" );
00051   m_parm_names.push_back ( "Quad" );
00052 
00053   resize ();
00054 }
00055 
00056 FunctionBase * Quadratic::clone () const
00057 {
00058   return new Quadratic ( *this );
00059 }
00060 
00061 double Quadratic::operator () ( double x ) const
00062 {
00063   return m_parms[0] + x * ( m_parms[1] + x * m_parms[2] );
00064 }
00065 
00066 /* virtual */
00067 void 
00068 Quadratic::
00069 initialParameters ( const FunctionHelper * helper )
00070 {
00071   double min_x = helper->minCoord ();
00072   double max_x = helper->maxCoord ();
00073 
00074   double min_y = helper->minValue ();
00075   double max_y = helper->maxValue ();
00076 
00077   m_parms[1] = ( max_y - min_y ) / ( max_x - min_x );
00078   m_parms[0] = max_y - m_parms[1] * max_x;
00079   m_parms[2] = m_parms[1] / ( 5.0 * ( max_x - min_x ) );
00080 }
00081 
00082 double Quadratic::derivByParm ( int i, double x ) const
00083 {
00084   switch ( i ) {
00085   case 0 :
00086     return 1.0;
00087     break;
00088 
00089   case 1 :
00090     return x; 
00091     break;
00092 
00093   case 2 :
00094     return x * x;
00095     break;
00096 
00097   default :
00098     assert (false );
00099     break;
00100   }
00101   return 0.0;
00102 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3