%% Nonlinear Solutions Example - Open Domain
% Fixed Point Method, two different roots

toler=0.00001;
alpha=40;
maxiter=100;

%% Fixed-Point Iteration (Good Root)
a=40;           % Guess
xl=20;          % Lower Bound for Plotting
xh=40;          % Upper Bound for Plotting
k=0;            % Zeroth Iteration
dphi=(xh-xl)/200;
phi=xl:dphi:xh;     % Plot range

while (abs(f(alpha,a))>toler) & (k<maxiter);
    k=k+1;
    a=g(alpha,a);
    % Plot
    figure(1); clf;
    plot(phi,phi,'g--',phi,g(alpha,phi),'k-');
    axis([min(phi) max(phi) xl xh]);
    hold on;
    plot(get(gca, 'xlim'),[0 0],'k:');   
    plot([a a], get(gca, 'ylim'),'b--');    
    text(a+10*dphi,a-15*dphi,['a=',num2str(a),char(10),'f(a)=',num2str(f(alpha,a)),char(10),'k=',num2str(k)],'FontSize',14);
    xlabel('\phi (deg.)');
    ylabel('f(\phi)');
    pause;
end;

%% Fixed-Point Iteration (Other Root)
a=20;           % Guess
xl=-20;         % Lower Bound for Plotting
xh=40;          % Upper Bound for Plotting
k=0;            % Zeroth Iteration
dphi=(xh-xl)/200;
phi=xl:dphi:xh;     % Plot range

while (abs(f(alpha,a))>toler) & (k<maxiter);
    k=k+1;
    a=gbad(alpha,a);
    % Plot
    figure(2); clf;
    plot(phi,phi,'g--',phi,gbad(alpha,phi),'k-');
    axis([min(phi) max(phi) xl xh]);
    hold on;
    plot(get(gca, 'xlim'),[0 0],'k:');   
    plot([a a], get(gca, 'ylim'),'b--');    
    text(a+10*dphi,a+15*dphi,['a=',num2str(a),char(10),'f(a)=',num2str(f(alpha,a)),char(10),'k=',num2str(k)],'FontSize',14);
    xlabel('\phi (deg.)');
    ylabel('f(\phi)');
    pause;
end;

