# HG changeset patch # User Sascha L. Teichmann # Date 1340104384 0 # Node ID c0abfb6953326557d0e5727de540ec81097e3c30 # Parent ef0dd585b5e0cabaa842c3fd7dcc76d98b2d5223 SQ: Add new power function. flys-artifacts/trunk@4699 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r ef0dd585b5e0 -r c0abfb695332 flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/artifacts/model/sq/SQMeasurementFacet.java: diff -r ef0dd585b5e0 -r c0abfb695332 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/FunctionFactory.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() { diff -r ef0dd585b5e0 -r c0abfb695332 flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/SQPow.java --- /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 :