001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.math.optimization.fitting; 019 020 import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction; 021 022 /** Harmonic function of the form <code>f (t) = a cos (ω t + φ)</code>. 023 * @version $Revision: 786479 $ $Date: 2009-06-19 08:36:16 -0400 (Fri, 19 Jun 2009) $ 024 * @since 2.0 025 */ 026 public class HarmonicFunction implements DifferentiableUnivariateRealFunction { 027 028 /** Amplitude a. */ 029 private final double a; 030 031 /** Pulsation ω. */ 032 private final double omega; 033 034 /** Phase φ. */ 035 private final double phi; 036 037 /** Simple constructor. 038 * @param a amplitude 039 * @param omega pulsation 040 * @param phi phase 041 */ 042 public HarmonicFunction(double a, double omega, double phi) { 043 this.a = a; 044 this.omega = omega; 045 this.phi = phi; 046 } 047 048 /** {@inheritDoc} */ 049 public double value(double x) { 050 return a * Math.cos(omega * x + phi); 051 } 052 053 /** {@inheritDoc} */ 054 public HarmonicFunction derivative() { 055 return new HarmonicFunction(a * omega, omega, phi + Math.PI / 2); 056 } 057 058 /** Get the amplitude a. 059 * @return amplitude a; 060 */ 061 public double getAmplitude() { 062 return a; 063 } 064 065 /** Get the pulsation ω. 066 * @return pulsation ω 067 */ 068 public double getPulsation() { 069 return omega; 070 } 071 072 /** Get the phase φ. 073 * @return phase φ 074 */ 075 public double getPhase() { 076 return phi; 077 } 078 079 }