% Systems of Nonlinear Algebraic Equations
% Nonlinear systems of algebraic equations are similar to linear systems, except the coefficients are not generally constants. It’s a small difference, but it has a huge impact on the nature of the solution. Specifically, nonlinear systems can have anywhere between 0 and an infinite number of solutions and the algorithms used to solve them are generally iterative. Consider the system below
%  \begin{array}{l}
% x^2 +2y^2 -5x+74=40\\
% 3x^2 -y^2 +4x+2y=28
% \end{array}
%  To solve this system, we convert it to two functions
% \begin{array}{l}
% {f\left(x,y\right)=x}^2 +2y^2 -5x+74-40\\
% g\left(x,y\right)=3x^2 -y^2 +4x+2y-28
% \end{array}
% The code to solve this system is

guess=[2 3];
[result, fval, exit, output]=fsolve(@eqns, guess);
xsolution=result(1)
ysolution=result(2)
str=sprintf('f(x,y)=%4.2e and g(x,y)=%4.2e at solution',fval(1), fval(2));
disp(str)
output

%

function fcns=eqns(z)
x=z(1);
y=z(2);
fcns(1)=x.^2+2*y.^2-5*x+7*y-40;
fcns(2)=3*x.^2-y.^2+4*x+2*y-28;
end

% © James Blanchard, University of Wisconsin-Madison, blanchard@engr.wisc.edu