简体   繁体   中英

Minimize univariate function in Java

My final goal is the minimization of a certain and given univariate function. For this I'm using Apache Commons Math .

Therefore, I actually have a class such as the following:

import org.apache.commons.math3.analysis.UnivariateFunction;
import com.imsl.math.JMath;


public class FindRoughness implements UnivariateFunction {

    final private double hubWindSpeed;
    final private double hubHeight;
    final private double latitude;
    final private double sigma_target;
    final private double OMEGA = 72.9E-06;  

    FindRoughness(double v, double z, double lat, double ti ){
        this.hubWindSpeed = v;
        this.hubHeight = z;
        this.latitude = lat*(JMath.PI/180);
        this.sigma_target = ti*this.hubWindSpeed/100;
    }

    private double calc_sigma( double z0){
        final double F = 2*OMEGA*JMath.sin(this.latitude);
        double ustar = ( .4*this.hubWindSpeed - 34.5*F*this.hubHeight )/JMath.log(this.hubHeight/z0);
        double mu = 1 - ( (6*F*this.hubHeight)/(ustar) );
        double p = JMath.pow(mu, 16);
        return ( sigma_target  - ((7.5*mu*ustar*JMath.pow((.538 + .09*JMath.log(this.hubHeight/z0)), p))/(1.0 + .156*JMath.log(ustar/(F*z0))))  );      

    }

    public double value(double z0){
        return calc_sigma(z0);
    }

    public UnivariateFunction find_z0(){
        return new UnivariateFunction(){
            public double value(double z0){
                return calc_sigma(z0);
            }
        };
    }
}

So given the constructor's parameters, and an initial value z0 , I would like to find out the exact value of z0 which let calc_sigma retrieve 0 .

Although I had more than just a look at he API, I still do not understand how to proceed and get the results I aim for.

Sorry a bit late. So you are trying to find the zeros for your univariate function. Looking at the function, it looks like numerical analysis is needed to find the zeros.

In Commons Math, there is a class BrentSolver which does this. Now there are a few different mathematical methods to find zeros, but this works with an API you are already using and has a description which matches your situation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM