clear; clc; close all;

ytarget=2;
xo = 1;
tol = 1e-4;

y=@(x)(5*x.^3-2*x);

xnew=@(x)((ytarget+10*x.^3)./(15*x.^2-2));

xpts=linspace(-1,1);
figure;
set(gca,'FontSize',18);

err=tol+1;
i=1;
while err>tol
  
  x=xnew(xo);
  
  fprintf('%1.0f  xo=%1.4f  x=%1.4f  y=%1.4f\n',i,xo,x,y(x));
  plot(xpts,y(xpts),...
    'k-',xo,y(xo),'ro',...
    x,y(x),'bx',...
    'LineWidth',2, 'MarkerSize',8); 
  grid on;
  title(strcat('k=',num2str(i)));
  xlabel('x'); ylabel('y'); legend('f(x)','xo','xnew','Location','best');
  
  xo = x;
  err=abs(y(x)-ytarget);
  i=i+1;
  
  pause;
end
fprintf('\nconverged!\n');