001: /*
002: * Copyright 2003-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.math.analysis;
017:
018: import org.apache.commons.discovery.tools.DiscoverClass;
019:
020: /**
021: * Abstract factory class used to create {@link UnivariateRealSolver} instances.
022: * <p>
023: * Solvers implementing the following algorithms are supported:
024: * <ul>
025: * <li>Bisection</li>
026: * <li>Brent's method</li>
027: * <li>Secant method</li>
028: * </ul>
029: * Concrete factories extending this class also specify a default solver, instances of which
030: * are returned by <code>newDefaultSolver()</code>.
031: * <p>
032: * Common usage:<pre>
033: * SolverFactory factory = UnivariateRealSolverFactory.newInstance();
034: *
035: * // create a Brent solver to use with a UnivariateRealFunction f
036: * BrentSolver solver = factory.newBrentSolver(f);
037: * </pre>
038: *
039: * <a href="http://jakarta.apache.org/commons/discovery/">Jakarta Commons Discovery</a>
040: * is used to determine the concrete factory returned by
041: * <code>UnivariateRealSolverFactory.newInstance().</code> The default is
042: * {@link UnivariateRealSolverFactoryImpl}.
043: *
044: * @version $Revision: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
045: */
046: public abstract class UnivariateRealSolverFactory {
047: /**
048: * Default constructor.
049: */
050: protected UnivariateRealSolverFactory() {
051: }
052:
053: /**
054: * Create a new factory.
055: * @return a new factory.
056: */
057: public static UnivariateRealSolverFactory newInstance() {
058: UnivariateRealSolverFactory factory = null;
059: try {
060: DiscoverClass dc = new DiscoverClass();
061: factory = (UnivariateRealSolverFactory) dc
062: .newInstance(UnivariateRealSolverFactory.class,
063: "org.apache.commons.math.analysis.UnivariateRealSolverFactoryImpl");
064: } catch (Throwable t) {
065: return new UnivariateRealSolverFactoryImpl();
066: }
067: return factory;
068: }
069:
070: /**
071: * Create a new {@link UnivariateRealSolver} for the given function. The
072: * actual solver returned is determined by the underlying factory.
073: * @param f the function.
074: * @return the new solver.
075: */
076: public abstract UnivariateRealSolver newDefaultSolver(
077: UnivariateRealFunction f);
078:
079: /**
080: * Create a new {@link UnivariateRealSolver} for the given function. The
081: * solver is an implementation of the bisection method.
082: * @param f the function.
083: * @return the new solver.
084: */
085: public abstract UnivariateRealSolver newBisectionSolver(
086: UnivariateRealFunction f);
087:
088: /**
089: * Create a new {@link UnivariateRealSolver} for the given function. The
090: * solver is an implementation of the Brent method.
091: * @param f the function.
092: * @return the new solver.
093: */
094: public abstract UnivariateRealSolver newBrentSolver(
095: UnivariateRealFunction f);
096:
097: /**
098: * Create a new {@link UnivariateRealSolver} for the given function. The
099: * solver is an implementation of Newton's Method.
100: * @param f the function.
101: * @return the new solver.
102: */
103: public abstract UnivariateRealSolver newNewtonSolver(
104: DifferentiableUnivariateRealFunction f);
105:
106: /**
107: * Create a new {@link UnivariateRealSolver} for the given function. The
108: * solver is an implementation of the secant method.
109: * @param f the function.
110: * @return the new solver.
111: */
112: public abstract UnivariateRealSolver newSecantSolver(
113: UnivariateRealFunction f);
114: }
|