disp (' This is the code of Muller method.Is written by Ali Ashouri') disp (' ') disp (' ') disp (' ********Before enter anything read all of introduction that will write. read all of them*******') disp (' ') format long disp (' x must be at double class . like: x=-1:0.00001:1') disp (' ') disp (' function should be start by @(x) like : @(x) sin(x)') disp (' ') x=input(' enter your variable for x : '); f=input('enter your function: '); k=input('enter the first number of limit : '); l=input('enter the final number of limit: '); d=input('Enter the epsilon or d number : '); tic disp (' ') disp (' ') double (x); n=1; x2=k; x1=l; x0=(x1+x2)./2; q=(x0-x1)/(x1-x2); a=q.*f(x0)-q*(1+q)*f(x1)+(q.^2)*(f(x2)); b=(2*q+1)*f(x0)-((1+q).^2)*f(x1)+(q.^2)*f(x2); c=(1+q)*f(x0); D=sqrt(b.^2-4*a*c); if abs(b+D) > abs(b-D), E = b+D; else E = b-D; end; xn=x0-(x0-x1)*2*c./(E); xn=real(xn); W={'n' ' ' 'min' ' ' 'max' ' ' 'x0' ' ' 'xn'}; B={n ' ' num2str(x2) ' ' num2str(x1) ' ' num2str(x0) ' ' num2str(xn) }; while abs(f(xn))>=d n=n+1; if xn>x0 x2=x0; x0=xn; else x1=x0; x0=xn; end; q=(x0-x1)/(x1-x2); a=q.*f(x0)-q*(1+q)*f(x1)+(q.^2)*(f(x2)); b=(2*q+1)*f(x0)-((1+q).^2)*f(x1)+(q.^2)*f(x2); c=(1+q)*f(x0); D=sqrt(b.^2-4*a*c); if abs(b+D) > abs(b-D), E = b+D; else E = b-D; end; xn=x0-(x0-x1)*2*c./(E); xn=real(xn); A(n-1,1)={n}; A(n-1,2)={' '}; A(n-1,3)={num2str(x2)}; A(n-1,4)={' '}; A(n-1,5)={num2str(x1)}; A(n-1,6)={' '}; A(n-1,7)={num2str(x0)}; A(n-1,8)={' '}; A(n-1,9)={num2str(xn)}; end; F={'-------' '--------' '------' '-------' '-------' '--------' '---------' '--------------' '---------------'}; Q=[W ; F ; B ; A]; disp(Q) disp(' ') disp([' The answer is : ',num2str(cell2mat(Q(n+2,9)))]) disp ([' n=',num2str(n)]) disp(' ') toc;