function mnhf_deflation_example() %MNHF_DEFLATION_EXAMPLE illustrates the use of the deflation technique for % finding multiple roots of the function defined in fn1. By plotting this % function, we know that there are four roots, not necessarily all unique. global root1 root2 root3 % Call secant root finding algorithm in succesion to determine the four % different roots of the function defined in fn1.m. root1 = mnhf_secant(@fn1,[-2.5 -1.5],1e-10,1) fprintf('\n\n') root2 = mnhf_secant(@fn2,[-2.5 -1.5],1e-10,1) fprintf('\n\n') root3 = mnhf_secant(@fn3,[-0.5 0.5],1e-10,1) fprintf('\n\n') root4 = mnhf_secant(@fn4,[-1.0 -0.5],1e-10,1) fprintf('\n\n') %%%%%%%%%%%%%%%%% function y1=fn1(x) % Function of x used in illustrating deflation technique. y1 = x.*(x+sqrt(pi)).^2.0.*(exp(-x)-2.0); %%%%%%%%%%%%%%%%% function y2=fn2(x) % Function of x used in illustrating deflation technique. global root1 y2 = fn1(x)./(x-root1); %%%%%%%%%%%%%%%%% function y3=fn3(x) % Function of x used in illustrating deflation technique. global root1 root2 y3 = fn1(x)./(x-root1)./(x-root2); %%%%%%%%%%%%%%%%% function y4=fn4(x) % Function of x used in illustrating deflation technique. global root1 root2 root3 y4 = fn1(x)./(x-root1)./(x-root2)./(x-root3);