matlab求解非线性方程组 fsolve - Solve system of nonlinear equations
最近有人问我matlab求解方程组的问题,
下面提供了fsolve函数help,但要有几点需要注意
1.方程组的有解性
2.方程组解是否唯一
3.x0的选取,如果解不唯一,不同的x0可能会得到不同的解
fsolve - Solve system of nonlinear equations
Equation
Solves a problem specified by
F(x) = 0
for x, where x is a vector and F(x) is a function that returns a vector value.
Syntax
x = fsolve(fun,x0)
x = fsolve(fun,x0,options)
x = fsolve(problem)
[x,fval] = fsolve(fun,x0)
[x,fval,exitflag] = fsolve(...)
[x,fval,exitflag,output] = fsolve(...)
[x,fval,exitflag,output,jacobian] = fsolve(...)
Description
fsolve finds a root (zero) of a system of nonlinear equations.
x = fsolve(fun,x0) starts at x0 and tries to solve the equations described in fun.
x = fsolve(fun,x0,options) solves the equations with the optimization options specified in the structure options. Use optimset to set these options.
x = fsolve(problem) solves problem, where problem is a structure described in Input Arguments.
Create the structure problem by exporting a problem from Optimization Tool, as described in Exporting to the MATLAB® Workspace.
[x,fval] = fsolve(fun,x0) returns the value of the objective function fun at the solution x.
[x,fval,exitflag] = fsolve(...) returns a value exitflag that describes the exit condition.
[x,fval,exitflag,output] = fsolve(...) returns a structure output that contains information about the optimization.
[x,fval,exitflag,output,jacobian] = fsolve(...) returns the Jacobian of fun at the solution x.
Passing Extra Parameters explains how to parameterize the objective function fun, if necessary.
Input Arguments
Function Arguments contains general descriptions of arguments passed into fsolve. This section provides function-specific details for fun and problem:
|
The nonlinear system of equations to solve. fun is a function that accepts a vector x and returns a vector F, the nonlinear equations evaluated at x. The function fun can be specified as a function handle for an M-file function x = fsolve(@myfun,x0) where myfun is a MATLAB® function such as function F = myfun(x)F = ... % Compute function values at x fun can also be a function handle for an anonymous function. x = fsolve(@(x)sin(x.*x),x0); If the user-defined values for x and F are matrices, they are converted to a vector using linear indexing. If the Jacobian can also be computed and the Jacobian option is 'on', set by options = optimset('Jacobian','on')
then the function fun must return, in a second output argument, the Jacobian value J, a matrix, at x. If fun returns a vector (matrix) of m components and x has length n, where n is the length of x0, then the Jacobian J is an m-by-n matrix where J(i,j) is the partial derivative of F(i) with respect to x(j). (Note that the Jacobian J is the transpose of the gradient of F.) |
||
| problem |
objective |
Objective function |
|
x0 |
Initial point for x | |
|
solver |
'fsolve' | |
|
options |
Options structure created with optimset | |
Output Arguments
Function Arguments contains general descriptions of arguments returned by fsolve. For more information on the output headings for fsolve, see Function-Specific Output Headings.
This section provides function-specific details for exitflag and output:
|
exitflag |
Integer identifying the reason the algorithm terminated. The following lists the values of exitflag and the corresponding reasons the algorithm terminated. |
|
|
1 |
Function converged to a solution x. |
|
|
2 |
Change in x was smaller than the specified tolerance. |
|
|
3 |
Change in the residual was smaller than the specified tolerance. |
|
|
4 |
Magnitude of search direction was smaller than the specified tolerance. |
|
|
0 |
Number of iterations exceeded options.MaxIter or number of function evaluations exceeded options.FunEvals. |
|
|
-1 |
Algorithm was terminated by the output function. |
|
|
-2 |
Algorithm appears to be converging to a point that is not a root. |
|
|
-3 |
Trust radius became too small. |
|
|
-4 |
Line search cannot sufficiently decrease the residual along the current search direction. |
|
|
output |
Structure containing information about the optimization. The fields of the structure are |
|
| iterations |
Number of iterations taken |
|
| funcCount |
Number of function evaluations |
|
| algorithm |
Optimization algorithm used. |
|
| cgiterations |
Total number of PCG iterations (large-scale algorithm only) |
|
| stepsize |
Final displacement in x (Gauss-Newton and Levenberg-Marquardt algorithms) |
|
| firstorderopt |
Measure of first-order optimality (dogleg or large-scale algorithm, [ ] for others) |
|
| message |
Exit message |
|

您当前的位置: