|
|
◆ hybrd1()
| function hybrd1 |
( |
f::Function |
, |
|
|
n::Integer |
, |
|
|
x::Array{Float64} |
, |
|
|
fvec::Array{Float64} |
, |
|
|
xtol::Real |
= 1.0e-10 |
|
) |
| |
Solution of a system of nonlinear equations by Powell hybrid method (Jacobian not required) (simple driver)
- Purpose
- hybrd1 finds a zero of a system of n nonlinear functions in n variables
fi(x1, x2, ..., xn) = 0 (i = 1 to n)
by a modification of the Powell hybrid method.
The user must provide a subroutine which calculates the functions. Since the Jacobian is calculated by a forward difference approximation within the routine, the user is not required to provide the Jacobian.
hybrd1 is the simple driver for standard use, which calls the hybrd with default parameters.
- Returns
- info (Int32)
= 0: Successful exit (relative error between two consecutive iterates is at most xtol)
= -1: The argument f is invalid. = -2: The argument n had an illegal value (n < 1)
= -3: The argument x is invalid. = -4: The argument fvec is invalid. = -5: The argument xtol had an illegal value (xtol < 0)
= 1: Number of calls to fcn with iflag = 1 or 2 has reached the limit (200*(n + 1))
= 2: xtol is too small. No further improvement in the approximate solution x is possible
= 3: Iteration is not making good progress, as measured by the improvement from the last five Jacobian evaluations
= 4: Iteration is not making good progress, as measured by the improvement from the last ten iterations
- Parameters
-
| [in] | f | User supplied subroutine which calculates the functions fi(x) defined as follows. _CODE function f(n, x, fvec, iflag) if iflag == 1 or iflag == 2 fvec[0] = function value f1(x[0], x[1], ..., x[n-1]) fvec[1] = function value f2(x[0], x[1], ..., x[n-1]) ... fvec[n-1] = function value fn(x[0], x[1], ..., x[n-1]) end end _ENDCODE When iflag = 1 or 2, calculate the function values fi(x) and set to fvec. |
| [in] | n | Number of functions and variables. (n > 0) |
| [in,out] | x | 1-dimensional array (Float64, n)
[in] An initial estimate of the solution vector.
[out] The obtained solution vector. |
| [out] | fvec | 1-dimensional array (Float64, n)
The function values evaluated at the solution vector x. |
| [in] | xtol | (Optional)
Target relative tolerance. Termination occurs when the relative error between two consecutive iterations is at most xtol. (xtol >= 0) (default = 1.0e-10) |
- Reference
- netlib/minpack
- Example Program
- Solve the following system of nonlinear equations.
x1^2 - x2 - 1 = 0
(x1 - 2)^2 + (x2 - 0.5)^2 - 1 = 0
The initial approximation (x1, x2) = (0, 0) is used. function fhybrd1(n, x, fvec, iflag)
fvec[1] = x[1]^2 - x[2] - 1
fvec[2] = (x[1] - 2)^2 + (x[2] - 0.5)^2 - 1
end
function TestHybrd1()
n = 2
x = [ 0.0, 0.0 ]
fvec = Vector{Cdouble}(undef, n)
info = hybrd1(fhybrd1, n, x, fvec)
println(x)
println(fvec)
println(info)
end
function hybrd1(f::Function, n::Integer, x::Array{Float64}, fvec::Array{Float64}, xtol::Real=1.0e-10) Solution of a system of nonlinear equations by Powell hybrid method (Jacobian not required) (simple d...
- Example Results
> TestHybrd1()
[1.0673460858066897, 0.13922766688686142]
[-1.1102230246251565e-16, 0.0]
0
|