Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/fitting/InvQuad.java @ 4789:0df2247d98e1
Create and add sieves regardless of the the order of diameter/value.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 09 Jan 2013 09:28:01 +0100 |
parents | de67497de5a0 |
children |
rev | line source |
---|---|
3177
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.math.fitting; |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 public class InvQuad |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 extends Function |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 { |
3181
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
6 public static final Derivative DERIVATIVE = |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
7 new Derivative("Q'(W) = 1/sqrt(4*n*(W-b)+m^2)") { |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
8 |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
9 @Override |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
10 public de.intevation.flys.artifacts.math.Function |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
11 instantiate(double [] parameters) |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
12 { |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
13 double n = parameters[0]; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
14 double m = parameters[1]; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
15 final double b = parameters[2]; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
16 final double n4 = 4d*n; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
17 final double mm = m*m; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
18 |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
19 return new de.intevation.flys.artifacts.math.Function() { |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
20 @Override |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
21 public double value(double W) { |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
22 return 1d/Math.sqrt(n4*(W-b)+mm); |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
23 } |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
24 }; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
25 } |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
26 }; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
27 |
3177
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 public static final Function INSTANCE = new InvQuad(); |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 public InvQuad() { |
3181
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
31 super( |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
32 "inv-quad", |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
33 "(sqrt(4*n*W-4*b*n+m^2)-m)/(2*n)", |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
34 new String [] { "n", "m", "b" }); |
3177
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 } |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 @Override |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 public double value(double W, double [] parameters) { |
3181
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
39 double n = parameters[0]; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
40 double m = parameters[1]; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
41 double b = parameters[2]; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
42 return (Math.sqrt(4d*n*(W - b) + m*m)-m)/(2d*n); |
3177
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 } |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 @Override |
3181
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
46 public double [] gradient(double W, double [] parameters) { |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
47 double n = parameters[0]; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
48 double m = parameters[1]; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
49 double b = parameters[2]; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
50 double Wb = W-b; |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
51 double sn4Wb = Math.sqrt(4d*n*Wb + m*m); |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
52 return new double [] { |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
53 Wb/(n*sn4Wb)-(sn4Wb-m)/(2d*n*n), |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
54 (m/sn4Wb-1d)/(2d*n), |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
55 -1d/sn4Wb |
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
56 }; |
3177
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 } |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 @Override |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 public Derivative getDerivative() { |
3181
de67497de5a0
Completed inverse functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3178
diff
changeset
|
61 return DERIVATIVE; |
3177
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 } |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 @Override |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 public Function getInverse() { |
3178
59b14bc676ec
Fitting: Link the functions to there inverses via getInverse().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3177
diff
changeset
|
66 return Quad.INSTANCE; |
3177
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 } |
585c0b49e696
Added inverses of the fitting functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |