001/*
002*   AbstractEvaluatable1D  -- A partial implementation of a 1D function y=fn(x) and it's slope dy/dx=d_fn(x)/dx.
003*
004*   Copyright (C) 1999 - 2012 by Joseph A. Huwaldt.
005*   All rights reserved.
006*   
007*   This library is free software; you can redistribute it and/or
008*   modify it under the terms of the GNU Lesser General Public
009*   License as published by the Free Software Foundation; either
010*   version 2 of the License, or (at your option) any later version.
011*   
012*   This library is distributed in the hope that it will be useful,
013*   but WITHOUT ANY WARRANTY; without even the implied warranty of
014*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015*   Lesser General Public License for more details.
016*
017*   You should have received a copy of the GNU Lesser General Public License
018*   along with this program; if not, write to the Free Software
019*   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020*   Or visit:  http://www.gnu.org/licenses/lgpl.html
021**/
022package jahuwaldt.tools.math;
023
024
025/**
026*  A class that defines a 1D function y = fn(x) (named
027*  "function") that can be called by math tools such as root
028*  finders.  Also defines the derivative of the function.
029*  dy/dx = d fn(x)/dx (oddly enough, named "derivative").
030*  An optional capability of setting an initial function value
031*  is also provided.  This aides the calculating of some
032*  functions and is a common enough problem that I've included
033*  it in the basic Evaluatable1D class definition.
034*
035*  <p>  Modified by:  Joseph A. Huwaldt  </p>
036*
037*  @author   Joseph A. Huwaldt   Date:  October 7, 1998
038*  @version  September 16, 2012
039**/
040public abstract class AbstractEvaluatable1D implements Evaluatable1D {
041        private double value0;
042        
043        
044        /**
045        *  Calculates the derivative of the function dy/dx = d fn(x)/dx.
046        *  Classes wanting to return the derivative of the function at x
047        *  should override this function.
048        *  If the method using this class doesn't require the
049        *  derivative, do nothing and Double.NaN is returned.
050        *
051        *  @param   x  Independent parameter to the function.
052        *  @return  The function value at x or Double.NaN if the derivative is not defined.
053        **/
054    @Override
055        public double derivative(double x) throws RootException {
056                return Double.NaN;
057        }
058        
059        
060        /**
061        *  Used to set an initial function value (or any other initial
062        *  value the user wants to use).  This function is provided as
063        *  an optional service.  The programmer may use this to aide in
064        *  solving problems where you want to find the point where
065        *  f(x) - f0 = 0.  Use this function to set f0 and use
066        *  "getInitialValue()" to retrieve f0 and calculate f(x) - f0 in
067        *  your "function()" definition.        </p>
068        *
069        *  @param  initialValue  Initial function value, f0.
070        **/
071        public void setInitialValue(double initialValue) {
072                value0 = initialValue;
073        }
074        
075
076        /**
077        *  Returns the initial function value set with "setInitialValue()".
078        *
079        *  @return  The initial value set with "setInitialValue()".
080        **/
081        public final double getInitialValue() {
082                return value0;
083        }
084        
085}
086
087
088