function root finding by secant method in matlab
<p>I have this matlab code for calculating the root of a function by using secant method :</p>

<pre><code>syms x
f=@(x) x.^2-2;
x0=1;
x1=5;
tol=0.01;

for i=1:100

    if (f(x0)-f(x1)) &lt; 0.00001
        break;
    end

xn = x0-((f(x0)*(x0-x1))/(f(x0)-f(x1)));

    if abs(xn-x0) &lt; tol*abs(xn)
       break;
    end
    x0=xn;
    x1=x0;
end


fprintf('the root is %g\n', xn)
</code></pre>

<p>When I run the code , matlab says : <code>Undefined function or variable 'xn'.</code>
Why it says that ? I did define the xn in the code !!!</p>

<p>thank you very much</p>