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