SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
AverageMathFunction.java
1/*
2 * Class: AverageMathFunction
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author Éric Buist
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.functions;
26
33public class AverageMathFunction implements MathFunction
34
36 private MathFunction[] func;
37
45 if (func == null)
46 throw new NullPointerException();
47 this.func = func.clone();
48 }
49
56 return func.clone();
57 }
58
59 public double evaluate(double x) {
60 double sum = 0;
61 for (final MathFunction fi : func)
62 sum += fi.evaluate(x);
63 return sum / func.length;
64 }
65
66 public double derivative(double x, int n) {
67 if (n < 0)
68 throw new IllegalArgumentException("n must be greater than or equal to 0");
69 if (n == 0)
70 return evaluate(x);
71 double sum = 0;
72 for (final MathFunction fi : func)
73 sum += MathFunctionUtil.derivative(fi, x, n);
74 return sum / func.length;
75 }
76
77 public double derivative(double x) {
78 double sum = 0;
79 for (final MathFunction fi : func)
80 sum += MathFunctionUtil.derivative(fi, x);
81 return sum / func.length;
82 }
83
84 public double integral(double a, double b) {
85 double sum = 0;
86 for (final MathFunction fi : func)
87 sum += MathFunctionUtil.integral(fi, a, b);
88 return sum / func.length;
89 }
90}
double derivative(double x)
Computes (or estimates) the first derivative of the function at point x.
double integral(double a, double b)
Computes (or estimates) the integral of the function over the interval .
double evaluate(double x)
Returns the value of the function evaluated at .
AverageMathFunction(MathFunction... func)
Constructs a function computing the average of the functions in the array func.
double derivative(double x, int n)
Computes (or estimates) the th derivative of the function at point x.
MathFunction[] getFunctions()
Returns the functions being averaged.
Provides utility methods for computing derivatives and integrals of functions.
static double derivative(MathFunction func, double x)
Returns the first derivative of the function func evaluated at x.
static double integral(MathFunction func, double a, double b)
Returns the integral of the function func over .
Represents a mathematical function whose th derivative can be computed using derivative(double,...
Represents a mathematical function whose derivative can be computed using derivative(double).
Represents a mathematical function whose integral can be computed by the integral(double,...
This interface should be implemented by classes which represent univariate mathematical functions.