view artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/InvSQPow.java @ 9643:58f3fe98fd6b

Fitting new Option UI
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Mon, 02 Dec 2019 14:14:06 +0100
parents af13ceeba52a
children
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.artifacts.math.fitting;

public class InvSQPow extends Function {
    public static final Derivative DERIVATIVE = new Derivative("Q'(S) = (S/a)^(1/b)/(b*S)") {

        @Override
        public org.dive4elements.river.artifacts.math.Function instantiate(final double[] parameters) {
            final double _1a = 1d / parameters[0];
            final double b = parameters[1];
            final double _1b = 1d / b;

            return new org.dive4elements.river.artifacts.math.Function() {
                @Override
                public double value(final double S) {
                    return Math.pow(S * _1a, _1b) / (b * S);
                }
            };
        }
    };
    public static final Function INSTANCE = new InvSQPow();

    public InvSQPow() {
        super("inv-special", "Q(S) = Q=(S/a)^(1/b)", new String[] { "a", "b" });
    }

    @Override
    public double value(final double S, final double[] parameters) {
        final double a = parameters[0];
        final double b = parameters[1];
        return Math.pow(S / a, 1d / b);
    }

    @Override
    public double[] gradient(final double S, final double[] parameters) {
        final double a = parameters[0];
        final double b = parameters[1];
        final double Sa = S / a;
        final double _1b = 1d / b;
        final double eSa1b = Math.pow(Sa, _1b);
        return new double[] { -eSa1b / (a * b), -(eSa1b * Math.log(Sa)) / (b * b) };
    }

    @Override
    public Derivative getDerivative() {
        return DERIVATIVE;
    }

    @Override
    public Function getInverse() {
        return SQPow.INSTANCE;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org