javamatlabmathematical-optimizationlevenberg-marquardt

Levenberg-Marquardt minimization in Java


I generally code in MATLAB, but for some reasons I decided to switch to a JAVA approach.

The question is quite easy: I'd like understanding how to translate the following MATLAB code into a working JAVA's one.

Within MATLAB I have a target function called findZ0:

function F = findZ0(V, Z, Latitude, TI, x)
%%% Inputs
% V = Average Wind Speed at Hub Height
% Z = Hub Height;
% Latitude = Specific Site Latitude (default value equal to 50 deg);
% x = Tryout Roughness length;
% TI = Target Turbulent Intensity;
%%% Outputs
% F = Roughness Length tuned to match Target Turbulent Intensity

Latitude = deg2rad(Latitude);
omega = 72.9E-06;
f = 2*omega*sin(Latitude);
ustar = ( 0.4*V - 34.5*f*Z)/log(Z/x);
mu = 1 - ((6*f*Z)/(ustar));
p = mu^(16);
sigmaTarget = (V*TI)/100;

F = sigmaTarget - (( 7.5*mu*ustar*((0.538 + .09*log(Z/x))^p) )/(1 + .156*log(ustar/(f*x))));
end

I then called this lines:

Uhub = 8;
HubHt = 90;
Latitude = 50;
x_trial = 0.01;
TI_target = 24;

find_z0 = @(x) findZ0(Uhub,HubHt,Latitude,TI_target, x);
z0 = fsolve(find_z0,x_trial,{'fsolve','Jacobian','on','levenberg-marquardt',.005,'MaxIter',15000,'TolX',1e-07,'TolFun',1E-07,'Display','off'});

I am aware that Fortran packages have been imported in Java, but I don't really have a clue how to achieve my goal by applying the mentioned tools. Hence, I'd welcome any suggestion on how to overcome this problem.


Solution

  • I'd suggest using an existing solution like Apache Commons - it's a robust library containing a lot of tools you may find helpful.

    The LM optimization method is implemented by this class - you can either use it directly or just look at it for inspiration.