% Root-Finding (Solving nonlinear algebraic equations in one dimension)
% Here we see how to numerically solve nonlinear algebraic equations. The general form of such equations is often written as:
%       f\left(x\right)=0                        ,
% which implies that our goal is to find a value for x such that the function f(x) is 0. Solutions to this equation are often referred to as roots. The key to root-finding is to first plot the function. Because we are considering nonlinear equations we can encounter functions that have no real roots (consider  x^2 +1=0), a finite number of roots (consider x-1=0 ) or an infinite number of roots (consider \sin \left(x\right)=0 ). So without first understanding our function, generally by plotting it in real space, we are doomed to failure.
% Root-Finding is generally an iterative process. That is we make a guess for our root and then successively improve our guess until we converge to a satisfactory solution.
% The Matlab function fzero solves for the roots of functions. To carry this out for \sin \left(x\right)=0,

x=-5:0.1:5;
y=f(x);
plot(x,y,[-5 5],[0 0])

%

guess=1
fzero(@f,guess)
guess=3
fzero(@f,guess)

%

function z=f(x)
z=sin(x);
end

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