% This is rough Mfile for secant method and of course needs to be changed % to a function and tested appropriately. % clear all clears all variables, etc in the memory clear all clc % Defining the inputs % function f(x) of the equation f(x)=0 (use functional notation for function) % maximum number of iterations, nmax % prespecified tolerance, tol % initial guess, older_guess % initial guess, old_guess f=inline('x^3-27') older_guess=236.7 old_guess=1233.4 nmax=10 tol=0.005 % Using a loop to conduct the recursion for i=1:1:nmax fprimenum=f(old_guess)-f(older_guess) fprimeden=old_guess-older_guess fprime=fprimenum/fprimeden % using the formula to calculate new guess new_guess=old_guess-f(old_guess)/fprime % calculating the absolute relative approximate error absea=abs((new_guess-old_guess)/new_guess)*100 % Checking if the absolute relative approximate error is less than the % tolerance if (absea