HYBRD_(3)
π HYBRD_(3) β hybrd_, hybrd1_ π
okay bestie, sit down, we're learning about finding zeros of nonlinear systems and honestly? it's giving iconic. this is a minpack.h situation, so grab your #include and let's go π¦
β¨ NAME β¨
hybrd_, hybrd1_ β find a zero of a system of nonlinear function (yes, "function", singular, that's what it says, we don't question the original, we respect it π )
πΈ SYNOPSIS πΈ
#include <minpack.h>
void hybrd1_ ( void (*fcn)( int *n, double *x,
double *fvec, int *iflag),
int *n, double *x, double *fvec,
double *tol, int *info, double *wa,
int *lwa);
void hybrd_ ( void (*fcn)( int * n, double *x,
double *fvec, int *iflag),
int *n, double *x, double *fvec,
double *xtol, int *maxfev, int *ml, int *mu,
double *epsfcn, double *diag, int *mode, double *factor,
int *nprint, int *info,
int *nfev, double *fjac, int *ldfjac,
double *r, int *lr, double *qtf,
double *wa1, double *wa2, double *wa3, double *wa4);
look at all those pointers. every single one. call-by-reference nation rise π«Ά
π DESCRIPTION π
so the whole point of hybrd_ is to find a zero of a system of n nonlinear functions in n variables, using a modification of the Powell hybrid method. the way it works: you supply a subroutine that calculates the functions, and then the Jacobian gets calculated by a forward-difference approximation. no analytic derivatives required, we're keeping it low-effort and high-reward β¨
hybrd1_ does the exact same thing but has a simplified calling sequence. same energy, fewer arguments, main character energy either way π
π Language notes π
hybrd_ and hybrd1_ are written in FORTRAN. so if you're calling from C, keep these points in mind, fr fr:
- Name mangling. β With
gfortran, all the function names end in an underscore. that's why there's a_bestie, it's not a typo, it's destiny. - Compile with
gfortran. β Even if your program is all C code, you should link withgfortranso it will pull in the FORTRAN libraries automatically. It's easiest just to usegfortranto do all the compiling. (It handles C just fine.) genuinely, just let it cook π - Call by reference. β All function parameters must be pointers. every last one. no escaping it.
- Column-major arrays. β okay so suppose a function returns an array with 5 rows and 3 columns in an array
zand in the call you have declared a leading dimension of7. the FORTRAN and equivalent C references are:
z(1,1) z[0]
z(2,1) z[1]
z(5,1) z[4]
z(1,2) z[7]
z(1,3) z[14]
z(i,j) z[(i-1) + (j-1)*7]
memorize the vibe. it's not chaos, it's just FORTRAN π
π« Parameters for both functions π«
fcnβ the name of the user-supplied subroutine which calculates the functions. In FORTRAN,fcnmust be declared in anexternalstatement in the user calling program, and should be written as follows:
subroutine fcn(n,x,fvec,iflag)
integer n,iflag
double precision x(n),fvec(n)
----------
calculate the functions at x and
return this vector in fvec.
---------
return
end
In C, fcn should be written as follows:
void fcn(int *n, double *x, double *fvec, int *iflag)
{
/* calculate the functions at x and
return this vector in fvec. */
}
π¨ the value ofiflagshould not be changed byfcnunless the user wants to terminate execution ofhybrd_. in this case setiflagto a negative integer. that's the eject button, use it with intention.
nβ a positive integer input variable set to the number of functions and variables. both. same number. that's the whole bit.xβ an array of lengthn. on inputxmust contain an initial estimate of the solution vector. on outputxcontains the final estimate of the solution vector. glow-up arc β¨fvecβ an output array of lengthnwhich contains the functions evaluated at the outputx.
π§ Parameters for hybrd1_ π§
tolβ a nonnegative input variable. termination occurs when the algorithm estimates that the relative error betweenxand the solution is at mosttol.infoβ an integer output variable. if the user has terminated execution,infois set to the (negative) value ofiflag. see description offcn. otherwise,infois set as follows.info = 0β improper input parameters.info = 1β algorithm estimates that the relative error betweenxand the solution is at mosttol.info = 2β number of calls tofcnhas reached or exceeded200*(n+1).info = 3βtolis too small. No further improvement in the approximate solutionxis possible.info = 4β iteration is not making good progress.
waβ a work array of lengthlwa.lwaβ a positive integer input variable not less than(n*(3*n+13))/2.
π Parameters for hybrd_ π
xtolβ a nonnegative input variable. termination occurs when the relative error between two consecutive iterates is at mostxtol.maxfevβ a positive integer input variable. termination occurs when the number of calls tofcnis at leastmaxfevby the end of an iteration.mlβ a nonnegative integer input variable which specifies the number of subdiagonals within the band of the jacobian matrix. if the Jacobian is not banded, setmlto at leastn - 1.muβ a nonnegative integer input variable which specifies the number of superdiagonals within the band of the jacobian matrix. if the jacobian is not banded, setmuto at leastn - 1.epsfcnβ an input variable used in determining a suitable step length for the forward-difference approximation. this approximation assumes that the relative errors in the functions are of the order ofepsfcn. ifepsfcnis less than the machine precision, it is assumed that the relative errors in the functions are of the order of the machine precision.diagβ an array of lengthn. ifmode = 1(see below),diagis internally set. ifmode = 2,diagmust contain positive entries that serve as multiplicative scale factors for the variables.modeβ an integer input variable. ifmode = 1, the variables will be scaled internally. ifmode = 2, the scaling is specified by the inputdiag. other values ofmodeare equivalent tomode = 1. (so like,mode = 7? it's a 1. we love a flexible king.)factorβ a positive input variable used in determining the initial step bound. this bound is set to the product offactorand the euclidean norm ofdiag*xif nonzero, or else tofactoritself. in most casesfactorshould lie in the interval(.1,100.).100.is a generally recommended value. take the rec, bestie.nprintβ an integer input variable that enables controlled printing of iterates if it is positive. in this case,fcnis called withiflag = 0at the beginning of the first iteration and everynprintiterations thereafter and immediately prior to return, withxandfvecavailable for printing. ifnprintis not positive, no special calls offcnwithiflag = 0are made.infoβ an integer output variable. if the user has terminated execution,infois set to the (negative) value ofiflag. see description offcn. otherwise,infois set as follows.info = 0β improper input parameters.info = 1β relative error between two consecutive iterates is at mostxtol.info = 2β number of calls tofcnhas reached or exceededmaxfev.info = 3βxtolis too small. No further improvement in the approximate solutionxis possible.info = 4β iteration is not making good progress, as measured by the improvement from the last five jacobian evaluations.info = 5β iteration is not making good progress, as measured by the improvement from the last ten iterations.
nfevβ an integer output variable set to the number of calls tofcn.fjacβ an outputnbynarray which contains the orthogonal matrixqproduced by the qr factorization of the final approximate jacobian.ldfjacβ a positive integer input variable not less thannwhich specifies the leading dimension of the arrayfjac.rβ an output array of lengthlrwhich contains the upper triangular matrix produced by the qr factorization of the final approximate Jacobian, stored rowwise.lrβ a positive integer input variable not less than(n*(n+1))/2.qtfβ an output array of lengthnwhich contains the vector(q transpose)*fvec.wa1,wa2,wa3, andwa4β work arrays of lengthn. four of them. little squad π
π₯ SEE ALSO π₯
hybrj(3)hybrj1(3)
π AUTHORS π
Burton S. Garbow, Kenneth E. Hillstrom, Jorge J. More.
this manual page was written by Jim Van Zandt <jrv@debian.org>, for the Debian GNU/Linux system (but may be used by others). iconic of him tbh.
okay that's the whole thing, you're basically a numerical analysis girlie now. go find your zeros, bestie. you got this π β¨
Minpack β March 8, 2002 β HYBRD_(3) πΈπ¦π
π¦ where this page comes from
- debian bookworm: minpack-dev 19961126+dfsg1-5 Β· BSD-4-clause-modified
- debian trixie: minpack-dev 19961126+dfsg1-5+b2 Β· BSD-4-clause-modified
- ubuntu jammy: minpack-dev 19961126+dfsg1-5build1 Β· BSD-4-clause-modified
- ubuntu noble: minpack-dev 19961126+dfsg1-5build1 Β· BSD-4-clause-modified
- ubuntu resolute: minpack-dev 19961126+dfsg1-5build2 Β· BSD-4-clause-modified
- ubuntu stonking: minpack-dev 19961126+dfsg1-5build2 Β· BSD-4-clause-modified
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms