在matlab的help中找fsolve,你会发现有一个例子在:
Example 1. This example finds a zero of the system of two equations and two unknowns Thus we want to solve the following system for x starting at x0 = [-5 -5]. First, write an M-file that computes F, the values of the equations at x.
function F = myfun(x)
F = [2*x(1) - x(2) - exp(-x(1));
-x(1) + 2*x(2) - exp(-x(2))];
Next, call an optimization routine.
x0 = [-5; -5]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
[x,fval] = fsolve(@myfun,x0,options) % Call optimizer |