DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ· RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=35950>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ· INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=35950 Summary: [math][patch] Add UnivariateRealIntegratorImpl.java Product: Commons Version: unspecified Platform: All OS/Version: All Status: NEW Severity: normal Priority: P1 Component: Math AssignedTo: [email protected] ReportedBy: [EMAIL PROTECTED] Index: src/java/org/apache/commons/math/analysis/UnivariateRealIntegratorImpl.java =================================================================== --- src/java/org/apache/commons/math/analysis/UnivariateRealIntegratorImpl.java (revision 0) +++ src/java/org/apache/commons/math/analysis/UnivariateRealIntegratorImpl.java (revision 0) @@ -0,0 +1,197 @@ +/* + * Copyright 2003-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.math.analysis; + +import java.io.Serializable; +import org.apache.commons.math.FunctionEvaluationException; + +/** + * Provide a default implementation for several generic functions. + * + * @version $Revision$ $Date: 2005-02-26 05:11:52 -0800 (Sat, 26 Feb 2005) $ + */ +public abstract class UnivariateRealIntegratorImpl implements UnivariateRealIntegrator, + Serializable { + + /** serializable version identifier */ + static final long serialVersionUID = -3365294665201465048L; + + /** maximum relative error */ + protected double relativeAccuracy; + + /** maximum number of iterations */ + protected int maximalIterationCount; + + /** default maximum relative error */ + protected double defaultRelativeAccuracy; + + /** default maximum number of iterations */ + protected int defaultMaximalIterationCount; + + /** indicates whether an integral has been computed */ + protected boolean resultComputed = false; + + /** the last computed integral */ + protected double result; + + /** the last iteration count */ + protected int iterationCount; + + /** the integrand function */ + protected UnivariateRealFunction f; + + /** + * Construct an integrator with given iteration count and accuracy. + * + * @param f the integrand function + * @param defaultMaximalIterationCount maximum number of iterations + * @param defaultRelativeAccuracy maximum relative error + * @throws IllegalArgumentException if f is null or the + * defaultRelativeAccuracy is not valid + */ + protected UnivariateRealIntegratorImpl( + UnivariateRealFunction f, + int defaultMaximalIterationCount, + double defaultRelativeAccuracy) { + + super(); + + if (f == null) { + throw new IllegalArgumentException("function can not be null."); + } + + this.f = f; + this.defaultRelativeAccuracy = defaultRelativeAccuracy; + this.relativeAccuracy = defaultRelativeAccuracy; + this.defaultMaximalIterationCount = defaultMaximalIterationCount; + this.maximalIterationCount = defaultMaximalIterationCount; + } + + /** + * Access the last computed integral. + * + * @return the last computed integral + * @throws IllegalStateException if no integral has been computed + */ + public double getResult() { + if (resultComputed) { + return result; + } else { + throw new IllegalStateException("No result available"); + } + } + + /** + * Access the last iteration count. + * + * @return the last iteration count + * @throws IllegalStateException if no integral has been computed + * + */ + public int getIterationCount() { + if (resultComputed) { + return iterationCount; + } else { + throw new IllegalStateException("No result available"); + } + } + + /** + * Convenience function for implementations. + * + * @param result the result to set + * @param iterationCount the iteration count to set + */ + protected final void setResult(double result, int iterationCount) { + this.result = result; + this.iterationCount = iterationCount; + this.resultComputed = true; + } + + /** + * Convenience function for implementations. + */ + protected final void clearResult() { + this.resultComputed = false; + } + + /** + * Set the upper limit for the number of iterations. + * + * @param count maximum number of iterations + */ + public void setMaximalIterationCount(int count) { + maximalIterationCount = count; + } + + /** + * Get the upper limit for the number of iterations. + * + * @return the actual upper limit + */ + public int getMaximalIterationCount() { + return maximalIterationCount; + } + + /** + * Reset the upper limit for the number of iterations to the default. + */ + public void resetMaximalIterationCount() { + maximalIterationCount = defaultMaximalIterationCount; + } + + /** + * Set the relative accuracy. + * + * @param accuracy the relative accuracy + * @throws IllegalArgumentException if the accuracy can't be achieved by + * the integrator or is otherwise deemed unreasonable + */ + public void setRelativeAccuracy(double accuracy) { + relativeAccuracy = accuracy; + } + + /** + * Get the actual relative accuracy. + * + * @return the accuracy + */ + public double getRelativeAccuracy() { + return relativeAccuracy; + } + + /** + * Reset the relative accuracy to the default. + */ + public void resetRelativeAccuracy() { + relativeAccuracy = defaultRelativeAccuracy; + } + + /** + * Verifies that the endpoints specify an interval. + * + * @param lower lower endpoint + * @param upper upper endpoint + * @throws IllegalArgumentException if not interval + */ + protected void verifyInterval(double lower, double upper) { + if (lower >= upper) { + throw new IllegalArgumentException + ("Endpoints do not specify an interval: [" + lower + + "," + upper + "]"); + } + } +} -- Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
