fortran-lang / minpack

Modernized Minpack: for solving nonlinear equations and nonlinear least squares problems
https://fortran-lang.github.io/minpack/
Other
96 stars 20 forks source link

Zero initialization is assumed! #6

Closed xecej4 closed 2 years ago

xecej4 commented 2 years ago

The driver programs do not assign zero initial values to the variable arrays x, Fvec and Fjac. Only the nonzero initial values are programmed. As a result, if the Fortran compiler in use does not provide a switch to do zero-initialization, or the user does not use the switch, the results will most probably be completely wrong.

Correcting this deficiency should also take care of issue #5.

jacobwilliams commented 2 years ago

Yep, these tests have not been modernized. Probably there are lot of things to fix. thanks for reporting this (and the others)

xecej4 commented 2 years ago

The fixes are quite simple. For the driver test_lmder.f90, here are the fixes.

Add the following as the first executable statement in subroutine SSQJAC: Fjac(1:m,1:n) = 0.0d0 Similarly, add as the first executable statement in INITPT: X(1:n) = 0.0d0 and as the first executable statement in SSQFCN: Fvec(1:m) = 0.d0

Similar changes apply to the other drivers. For test_lmstr.f90, add ",Save" to the declaration of TEMP in subroutine FCN.

jacobwilliams commented 2 years ago

I'm not quite seeing why the temp needs a save attribute.

jacobwilliams commented 2 years ago

oh wait...I just saw #7.

awvwgk commented 2 years ago

In the C test I solved this by introducing more cases and actually calculate the Jacobian row by row rather than once and rely on save / static to retrieve the previously calculated values.