Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/SQPow.java @ 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 | |
children | 6391ca82141c |
comparison
equal
deleted
inserted
replaced
3099:ef0dd585b5e0 | 3100:c0abfb695332 |
---|---|
1 package de.intevation.flys.artifacts.math.fitting; | |
2 | |
3 public class SQPow | |
4 extends Function | |
5 { | |
6 public static final Derivative DERIVATIVE = | |
7 new Derivative("W'(Q) = a*b*Q^(b-1)") { | |
8 | |
9 @Override | |
10 public de.intevation.flys.artifacts.math.Function | |
11 instantiate(double [] parameters) | |
12 { | |
13 final double a = parameters[0]; | |
14 final double b = parameters[1]; | |
15 | |
16 return new de.intevation.flys.artifacts.math.Function() { | |
17 @Override | |
18 public double value(double Q) { | |
19 return a*b*Math.pow(Q, b-1); | |
20 } | |
21 }; | |
22 } | |
23 }; | |
24 | |
25 public SQPow() { | |
26 super( | |
27 "sq-pow", | |
28 "S(Q) = a*Q^b", | |
29 new String [] { "a", "b" }); | |
30 } | |
31 | |
32 @Override | |
33 public double value(double x, double [] parameters) { | |
34 return parameters[0]*Math.pow(x, parameters[1]); | |
35 } | |
36 | |
37 @Override | |
38 public double [] gradient(double q, double [] parameters) { | |
39 double a = parameters[0]; | |
40 double b = parameters[1]; | |
41 double q_b = Math.pow(q, b); | |
42 return new double [] { | |
43 q_b, | |
44 a*q_b*Math.log(q), | |
45 }; | |
46 } | |
47 | |
48 @Override | |
49 public Derivative getDerivative() { | |
50 return DERIVATIVE; | |
51 } | |
52 } | |
53 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |