Here is the code I have.
function[root,ea,iter]=secant(func,delta,xr,es,maxit,varargin)if nargin<3,error('atleast 3 input arguments required'),endif nargin<4|isempty(es),es=0.0001;endif nargin<5|isempty(maxit),maxit=50;enditer=0;T=[]while (1) xrold=xr; xr=xr-((delta*xr*func(xr))/(func(xr+(delta*xr))-func(xr))); iter=iter+1; if xr~=0, ea=abs((xr-xrold)/xr)*100;end if ea<=es|iter>=maxit,break,end funcxr=func(xr); T=[T;[iter,xr,func(xr),ea]];endTroot=xr;
Here is the output.
>> secant(@(x) 6*x^2-13*x-5,10^-6,1.2)T = []T = 1.0000 9.7428 437.8779 87.6832 2.0000 5.5290 106.5398 76.2143 3.0000 3.5319 23.9303 56.5448 4.0000 2.7174 3.9799 29.9710 5.0000 2.5145 0.2472 8.0718 6.0000 2.5001 0.0012 0.5757 7.0000 2.5000 0.0000 0.0029ans = 2.5000
I need to have headings on the top of the colmuns and have no clue how to add them. Please help
Best Answer