21.07.2013 Views

nr. 477 - 2011 - Institut for Natur, Systemer og Modeller (NSM)

nr. 477 - 2011 - Institut for Natur, Systemer og Modeller (NSM)

nr. 477 - 2011 - Institut for Natur, Systemer og Modeller (NSM)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C.2 Code <strong>for</strong> the Newton-Raphson Method 167<br />

real(V_14),imag(V_14),’*b’,real(V_15),imag(V_15),’*b’,<br />

real(V_19),imag(V_19),’*b’,real(V_20),imag(V_20),’*b’,<br />

real(V_39),imag(V_39),’*b’,<br />

real(V_40),imag(V_40),’*b’)%k,0,’b’...<br />

axis([-1 1 -0.5 0.5 ])<br />

Title(’Plot of eigenvalues <strong>for</strong> the Jacobian evaluated in<br />

the upper inflamed region’)<br />

xlabel(’real(eig)’)<br />

ylabel(’img(eig)’)<br />

%--------------------------------------<br />

C.2 Code <strong>for</strong> the Newton-Raphson Method<br />

The code <strong>for</strong> the Newton-Raphson method. This is adapted from Shampine et al.<br />

(2003).<br />

function root = newtonRaphson2(func,M,tol)<br />

% Newton-Raphson method of finding a root of simultaneous<br />

% equations fi(x1,x2,...,xn) = 0, i = 1,2,...,n.<br />

% USAGE: root = newtonRaphson2(func,x,tol)<br />

% INPUT:<br />

% func = handle of function that returns[f1,f2,...,fn].<br />

% x = starting solution vector [x1,x2,...,xn].<br />

% tol = error tolerance (default is 1.0e4*eps).<br />

% OUTPUT:<br />

% root = solution vector.<br />

%define global<br />

%global g;<br />

Q=M;<br />

if nargin == 2; tol = 1.0e7*eps; end %NARGIN defines the<br />

number of input arguments that were used to call the function<br />

(M,tol). %Tol is the error tolerance <strong>for</strong> the computation<br />

here set to 1.0e4*eps = 2.2204e-012<br />

%if size(M,1) == 1; M = M’; end % M must be column vector<br />

(ctranspose - Complex conjugate transpose [’] ). if 3==1??<br />

%<strong>for</strong> i = 1:50

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!