Personal tools

NewtonRaphson.m

NewtonRaphson.m — Objective-C source code, 1Kb

File contents

function [t,F,qstar,iter] = NewtonRaphson(Xk,Fk)
 
global TOE


Xerr = Fk-Xk                            % StrideMap Error

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Newton-Raphson Algorithm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MaxAbsError = max(abs(Xerr));            % Max Absolute Error, serves as a  
                                            % termination condition
MaxAbsErrorOld = MaxAbsError;

% If you happen to guess an initial condition that is a fixed point, calculate 
% the following:
if MaxAbsError <= TOE
    [t,F,Fk] = StrideMap(Xk);
    qstar = Fk;
end

% Otherwise, if max(Xerr) > TOE, search for a fixed point
iter = 0;                                % dummy index
while MaxAbsError >= TOE && iter <= 50   % while loop exit condition
    
    iter = iter + 1;                     % counts # of loop executions
    dX = NewtonStep(Xk,Fk);              % computes Newton step
    
    Xk = Xk + dX;                        % new initial state vector
    [t,F,Fk] = StrideMap(Xk);            % Evaluates StrideMap
    Xerr = Fk-Xk                        % StrideMap Error;  
    MaxAbsError = max(abs(Xerr)); 
    if MaxAbsErrorOld <=  MaxAbsError
        iter = iter + 50;
    end
   
end



if MaxAbsError <= TOE && iter <= 50
    qstar = Fk;
else
    t = 0;
    F = zeros(1,length(Xk));
    qstar = zeros(size(Xk));
end


end






Document Actions