clear close all figure(1) x=0:0.01:1; plot(x,x-cos(x)),grid a=0; b=1; fa=a-cos(a); fb=b-cos(b); n=10; for jj=1:n m=(a+b)/2; mm(jj)=(a+b)/2; akurve(jj)=a; bkurve(jj)=b; fm=m-cos(m); fmid(jj)=fm; if sign(fa)==sign(fm), a=m; else b=m; end end xbisection=mm; x=1:n; figure(2) plot(x,mm,'.k',x,akurve,'*r',x,bkurve,'*r') xold=0.5; xnewton(1)=xold; fnewton(1)=xold-cos(xold); for jj=1:n xny=xold-(xold-cos(xold))/(1+sin(xold)); xold=xny; xnewton(jj+1)=xold; fnewton(jj+1)=xold-cos(xold); end format long xbisection xnewton format x=0.73908513321515; figure(3) subplot(2,1,1) xakse=1:n; plot(xakse,abs(x-xbisection),'.',xakse,abs(x-xnewton(1:end-1)),'.') subplot(2,1,2) plot(xakse,abs(x-xbisection)/x,'.',xakse,abs(x-xnewton(1:end-1))/x,'.')