I wrote the code for the secant algorithm , and now I have the function :
f(x) = 2x^3 - 4x^2 + 3x , with two initial points : x0 = -1 , x1 = 2 .
My question is how can I plot the function that I wrote ,i.e. secant , with the function above , f , and the results below , in one graph ?
Is it even possible to do that ?
The results that I got after I used the secant algorithm , are :
v =
-4.0000
2.2069
2.3699
2.6617
2.5683
2.5804
Those are 6 iterations that I used on my secant algorithm , for the given x0 & x1 above .
I’d appreciate if you can explain .
EDIT :
This is the code that I used in order to get the results :
[z,n,v]=secant([-1,2],10^(-5),10^(-5),10)
for the prototype :
function [x,n,v]=secant(X,d,e,N)
% x0 is the first point
% x1 is the end point
% d is the tolerance
% e is the requested precision
% N is the number of iterations
Thanks .
I quickly threw this together, it illustrates the powerful anonymous function
and it shows you how to plot the results of the secant function (the same way as on wikipedia: http://en.wikipedia.org/wiki/File:Secant_method.svg)
What I don’t understand however is why your secant function has both a tolerance and a requested precision as an input; I would think the tolerance is the result of the secant algorithm..