changeset 3100:c0abfb695332

SQ: Add new power function. flys-artifacts/trunk@4699 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 19 Jun 2012 11:13:04 +0000
parents ef0dd585b5e0
children b31397addf2f
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/FunctionFactory.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/SQPow.java
diffstat 3 files changed, 62 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jun 19 10:26:26 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jun 19 11:13:04 2012 +0000
@@ -1,3 +1,11 @@
+2012-06-19	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/math/fitting/SQPow.java:
+	  New. S(Q) = a*Q^b
+
+	* src/main/java/de/intevation/flys/artifacts/math/fitting/FunctionFactory.java:
+	  Registered new function.
+
 2012-06-19  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/sq/SQMeasurementFacet.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/FunctionFactory.java	Tue Jun 19 10:26:26 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/FunctionFactory.java	Tue Jun 19 11:13:04 2012 +0000
@@ -19,6 +19,7 @@
         registerFunction(new Exp());
         registerFunction(new Quad());
         registerFunction(new Pow());
+        registerFunction(new SQPow());
     }
 
     public static synchronized FunctionFactory getInstance() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/SQPow.java	Tue Jun 19 11:13:04 2012 +0000
@@ -0,0 +1,53 @@
+package de.intevation.flys.artifacts.math.fitting;
+
+public class SQPow
+extends      Function
+{
+    public static final Derivative DERIVATIVE =
+        new Derivative("W'(Q) = a*b*Q^(b-1)") {
+
+        @Override
+        public de.intevation.flys.artifacts.math.Function
+            instantiate(double [] parameters)
+        {
+            final double a = parameters[0];
+            final double b = parameters[1];
+
+            return new de.intevation.flys.artifacts.math.Function() {
+                @Override
+                public double value(double Q) {
+                    return a*b*Math.pow(Q, b-1);
+                }
+            };
+        }
+    };
+
+    public SQPow() {
+        super(
+            "sq-pow",
+            "S(Q) = a*Q^b",
+            new String [] { "a", "b" });
+    }
+
+    @Override
+    public double value(double x, double [] parameters) {
+        return parameters[0]*Math.pow(x, parameters[1]);
+    }
+
+    @Override
+    public double [] gradient(double q, double [] parameters) {
+        double a   = parameters[0];
+        double b   = parameters[1];
+        double q_b = Math.pow(q, b);
+        return new double [] {
+            q_b,
+            a*q_b*Math.log(q),
+        };
+    }
+
+    @Override
+    public Derivative getDerivative() {
+        return DERIVATIVE;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org