主题:求助,解方程加限制条件.....急!!!!
Melson
[专家分:0] 发布于 2007-11-07 14:24:00
请教各位大大,我要解一个方程组,其中海有超越方程,怎么加限制条件?
用的指令是不是solve
3 楼
allocate [专家分:540] 发布于 2007-11-09 18:16:00
help fsolve
FSOLVE solves systems of nonlinear equations of several variables.
FSOLVE attempts to solve equations of the form:
F(X)=0 where F and X may be vectors or matrices.
X=FSOLVE(FUN,X0) starts at the matrix X0 and tries to solve the
equations in FUN. FUN accepts input X and returns a vector (matrix) of
equation values F evaluated at X.
X=FSOLVE(FUN,X0,OPTIONS) solves the equations with the default optimization
parameters replaced by values in the structure OPTIONS, an argument
created with the OPTIMSET function. See OPTIMSET for details. Used
options are Display, TolX, TolFun, DerivativeCheck, Diagnostics,
FunValCheck, Jacobian, JacobMult, JacobPattern, LineSearchType,
NonlEqnAlgorithm, MaxFunEvals, MaxIter, OutputFcn, DiffMinChange and
DiffMaxChange, LargeScale, MaxPCGIter, PrecondBandWidth, TolPCG, and
TypicalX. Use the Jacobian option to specify that FUN also returns a
second output argument J that is the Jacobian matrix at the point X. If
FUN returns a vector F of m components when X has length n, then 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.)
[X,FVAL]=FSOLVE(FUN,X0,...) returns the value of the equations FUN at X.
[X,FVAL,EXITFLAG]=FSOLVE(FUN,X0,...) returns an EXITFLAG that describes the
exit condition of FSOLVE. Possible values of EXITFLAG and the corresponding
exit conditions are
1 FSOLVE converged to a solution X.
2 Change in X smaller than the specified tolerance.
3 Change in the residual smaller than the specified tolerance.
4 Magnitude of search direction smaller than the specified tolerance.
0 Maximum number of function evaluations or iterations reached.
-1 Algorithm terminated by the output function.
-2 Algorithm seems to be converging to a point that is not a root.
-3 Trust region radius became too small.
-4 Line search cannot sufficiently decrease the residual along the current
search direction.
[X,FVAL,EXITFLAG,OUTPUT]=FSOLVE(FUN,X0,...) returns a structure OUTPUT
with the number of iterations taken in OUTPUT.iterations, the number of
function evaluations in OUTPUT.funcCount, the algorithm used in OUTPUT.algorithm,
the number of CG iterations (if used) in OUTPUT.cgiterations, the first-order
optimality (if used) in OUTPUT.firstorderopt, and the exit message in
OUTPUT.message.
[X,FVAL,EXITFLAG,OUTPUT,JACOB]=FSOLVE(FUN,X0,...) returns the
Jacobian of FUN at X.
Examples
FUN can be specified using @:
x = fsolve(@myfun,[2 3 4],optimset('Display','iter'))
where myfun is a MATLAB function such as:
function F = myfun(x)
F = sin(x);
FUN can also be an anonymous function:
x = fsolve(@(x) sin(3*x),[1 4],optimset('Display','off'))
If FUN is parameterized, you can use anonymous functions to capture the
problem-dependent parameters. Suppose you want to solve the system of
nonlinear equations given in the function myfun, which is parameterized
by its second argument c. Here myfun is an M-file function such as
function F = myfun(x,c)
F = [ 2*x(1) - x(2) - exp(c*x(1))
-x(1) + 2*x(2) - exp(c*x(2))];
To solve the system of equations for a specific value of c, first assign the
value to c. Then create a one-argument anonymous function that captures
that value of c and calls myfun with two arguments. Finally, pass this anonymous
function to FSOLVE:
c = -1; % define parameter first
x = fsolve(@(x) myfun(x,c),[-5;-5])
See also OPTIMSET, LSQNONLIN, @, INLINE.