This example solves the system of two equations and two unknowns:
Rewrite the equations in the form F(x) = 0:
Start your search for a solution at x0 = [-5 -5].
First, write a 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))];
Save this function file as myfun.m somewhere on your MATLAB path. Next, set up the initial point and options and call fsolve:
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 solver
After several iterations, fsolve finds an answer:
Norm of First-order Trust-region
Iteration Func-count f(x) step optimality radius
0 3 23535.6 2.29e+004 1
1 6 6001.72 1 5.75e+003 1
2 9 1573.51 1 1.47e+003 1
3 12 427.226 1 388 1
4 15 119.763 1 107 1
5 18 33.5206 1 30.8 1
6 21 8.35208 1 9.05 1
7 24 1.21394 1 2.26 1
8 27 0.016329 0.759511 0.206 2.5
9 30 3.51575e-006 0.111927 0.00294 2.5
10 33 1.64763e-013 0.00169132 6.36e-007 2.5
Equation solved.
结果如下
Optimizer appears to be converging to a minimum that is not a root:
Sum of squares of the function values is > sqrt(options.TolFun).
Try again with a new starting point.
初值
4.7300
0.2119 - 7.2609i
3.0767 -24.8515i
要怎么办才好呢
[ 本帖最后由 ChaChing 于 2010-6-13 22:05 编辑 ] |