%% Examine Matrix Equation Solution
% Find a matrix X that satisfies
% \[X*X*X = \left[ {\begin{array}{*{20}{c}}
% 1&2\\
% 3&4
% \end{array}} \right]\],
% starting at the point x0 = [1,1;1,1]. Create an anonymous function that calculates the matrix equation and create the point x0.

fun = @(x)x*x*x - [1,2;3,4];
x0 = ones(2);

% Set options to have no display.

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

% Examine the fsolve outputs to see the solution quality and process.

[x,fval,exitflag,output] = fsolve(fun,x0,options)

% The exit flag value 1 indicates that the solution is reliable. To verify this manually, calculate the residual (sum of squares of fval) to see how close it is to zero.

sum(sum(fval.*fval))

% This small residual confirms that x is a solution.
% You can see in the output structure how many iterations and function evaluations fsolve performed to find the solution.
% Copyright 2019 The MathWorks, Inc.