Home > K25104 > ODEs > multistep_order.m

multistep_order

PURPOSE ^

Computes the order of the multistep method defined by the coefficients in rho and sigma.

SYNOPSIS ^

function [ p ] = multistep_order( rho,sigma )

DESCRIPTION ^

 Computes the order of the multistep method defined by the coefficients in rho and sigma.
 Input arguments:
   rho, sigma, column vectors prescribing the method. 
     The first element should contain the coefficient associated with l=0.
 Output arguments:
   p, order of the method

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ p ] = multistep_order( rho,sigma )
0002 % Computes the order of the multistep method defined by the coefficients in rho and sigma.
0003 % Input arguments:
0004 %   rho, sigma, column vectors prescribing the method.
0005 %     The first element should contain the coefficient associated with l=0.
0006 % Output arguments:
0007 %   p, order of the method
0008 
0009 % check user inputs
0010 [n,m]=size(rho);    % finding the size of rho
0011 [s,t]=size(sigma);  % finding the size of sigma
0012 if m~=1 || t~=1;
0013     error('inputs must be column vectors');
0014 elseif n~=s;
0015     error('input vectors must be the same length');
0016 end
0017 
0018 if sum(rho)~=0;
0019     disp(['first order condition not satisfied']);
0020     p=0; return;
0021 end
0022 
0023 k=1;    % initialize k
0024 term=0; 
0025 
0026 while term==0;
0027     a=0; b=0;   % initialize a,b
0028     for l=0:s-1;
0029         a=a+(l^k)*rho(l+1);
0030         b=b+(l^(k-1))*sigma(l+1);
0031     end
0032     b=k*b;
0033     if abs(a-b)<1e-12;  % not comparing to zero incase of rounding errors
0034         k=k+1;
0035     else
0036         term=1;
0037     end
0038 end
0039 
0040 p=k-1;
0041 
0042 end
0043         
0044

Generated on Mon 18-Jan-2016 10:25:49 by m2html © 2005