%% Solution Process of Nonlinear System
% This example returns the iterative display showing the solution process for the system of two equations and two unknowns
% \[\begin{array}{c}
% 2{x_1} - {x_2} = {e^{ - {x_1}}}\\
%  - {x_1} + 2{x_2} = {e^{ - {x_2}}}.
% \end{array}\]
% Rewrite the equations in the form F(x) = 0:
% \[\begin{array}{c}
% 2{x_1} - {x_2} - {e^{ - {x_1}}} = 0\\
%  - {x_1} + 2{x_2} - {e^{ - {x_2}}} = 0.
% \end{array}\]
% Start your search for a solution at x0 = [-5 -5].
% First, write a function that computes F, the values of the equations at x.

F = @(x) [2*x(1) - x(2) - exp(-x(1));
         -x(1) + 2*x(2) - exp(-x(2))];

% Create the initial point x0.

x0 = [-5;-5];

% Set options to return iterative display.

options = optimoptions('fsolve','Display','iter');

% Solve the equations.

[x,fval] = fsolve(F,x0,options)

% The iterative display shows f(x), which is the square of the norm of the function F(x). This value decreases to near zero as the iterations proceed. The first-order optimality measure likewise decreases to near zero as the iterations proceed. These entries show the convergence of the iterations to a solution. For the meanings of the other entries, see Iterative Display.
% The fval output gives the function value F(x), which should be zero at a solution (to within the FunctionTolerance tolerance).
% Copyright 2019 The MathWorks, Inc.