umontreal.iro.lecuyer.functions.SquareMathFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ssj Show documentation
Show all versions of ssj Show documentation
SSJ is a Java library for stochastic simulation, developed under the direction of Pierre L'Ecuyer,
in the Département d'Informatique et de Recherche Opérationnelle (DIRO), at the Université de Montréal.
It provides facilities for generating uniform and nonuniform random variates, computing different
measures related to probability distributions, performing goodness-of-fit tests, applying quasi-Monte
Carlo methods, collecting (elementary) statistics, and programming discrete-event simulations with both
events and processes.
The newest version!
/*
* Class: SquareMathFunction
* Description: function computing the square of another function
* Environment: Java
* Software: SSJ
* Copyright (C) 2001 Pierre L'Ecuyer and Université de Montréal
* Organization: DIRO, Université de Montréal
* @author Éric Buist
* @since
* SSJ is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License (GPL) as published by the
* Free Software Foundation, either version 3 of the License, or
* any later version.
* SSJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* A copy of the GNU General Public License is available at
GPL licence site.
*/
package umontreal.iro.lecuyer.functions;
/**
* Represents a function computing
*
* (af (x) + b)2 for a user-defined function
* f (x).
*
*/
public class SquareMathFunction implements MathFunctionWithFirstDerivative {
private MathFunction func;
private double a, b;
/**
* Constructs a new square function
* for function func.
* The values of the constants are
* a = 1 and b = 0.
*
* @param func the function f (x).
*
*
*/
public SquareMathFunction (MathFunction func) {
this (func, 1, 0);
}
/**
* Constructs a new power function
* for function func, and constants
* a and b.
*
* @param func the function f (x).
*
* @param a <
* #30#>the multiplicative constant.
* @param b the additive constant.
*
*
*/
public SquareMathFunction (MathFunction func, double a, double b) {
if (func == null)
throw new NullPointerException();
this.func = func;
this.a = a;
this.b = b;
}
/**
* Returns the function f (x).
*
* @return the function.
*
*/
public MathFunction getFunction() {
return func;
}
/**
* Returns the value of a.
*
* @return the value of a.
*
*/
public double getA() {
return a;
}
/**
* Returns the value of b.
*
* @return the value of b.
*
*/
public double getB() {
return b;
}
public double evaluate (double x) {
final double v = a*func.evaluate (x) + b;
return v*v;
}
public double derivative (double x) {
final double fder = MathFunctionUtil.derivative (func, x);
return 2*a*(a*func.evaluate (x) + b)*fder;
}
}