%This is the fixed point iteration 
% of the function f(x)=(3x+18)^(1/3)'
disp('This is the fixed point iteration of the function f(x)=(3x+18)^(1/3)')
disp('You may change the number of iterations and the initial value x_0')
     disp('Suggested starting values are n=20 and x_0=0')
n=input('Enter a value for n, total number of iterations: ');
x=zeros(1,n+1);
x(1)=input('Enter a value for x_0: ');
for i=1:n;
x(i+1)=(3*x(i)+18)^(1/3);
if isreal(x(i+1))==0
x(i+1)=-abs(x(i+1));
end
end
subplot(2,1,1)
plot(x,'-*','linewidth',2)
     axis([0,n,0,x(1)+4])
     title('Iterations of fixed point map')
     xlabel('Iteration, i','fontsize',18)
     ylabel('x_i','fontsize',18)
     subplot(2,2,3)
     xs=0:0.1:20;
     fs=(3*xs+18).^(1/3);
     plot(xs,fs,xs,xs,'linewidth',2)
     title('plot of y=f(x) and y=x,')
     xlabel('x')
     ylabel('y')
     axis([0,20,0,20])
     subplot(2,2,4)
     plot(log10(abs(x-3)),'-*','linewidth',2)
     title('log plot of Error for iteration')
     xlabel('Iteration, i','fontsize',18)
     ylabel('log_{10}|Error_i|','fontsize',18)
     axis([0,n,-20,10])

