diff --git a/matlab/AIM/SPAmalg.m b/matlab/AIM/SPAmalg.m
index 6438cf39b8a06232670cd4ff7b716cb7742ecfcc..41307b445e118ca8721e93952706d9be876bdc5e 100644
--- a/matlab/AIM/SPAmalg.m
+++ b/matlab/AIM/SPAmalg.m
@@ -1,3 +1,5 @@
+function [b,rts,ia,nexact,nnumeric,lgroots,aimcode] = ...
+                        SPAmalg(h,neq,nlag,nlead,condn,uprbnd)
 %  [b,rts,ia,nexact,nnumeric,lgroots,aimcode] = ...
 %                       SPAmalg(h,neq,nlag,nlead,condn,uprbnd)
 %
@@ -54,8 +56,6 @@
 % Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3,
 % pages 472-489
 
-function [b,rts,ia,nexact,nnumeric,lgroots,aimcode] = ...
-                        SPAmalg(h,neq,nlag,nlead,condn,uprbnd)
 b=[];rts=[];ia=[];nexact=[];nnumeric=[];lgroots=[];aimcode=[];
 if(nlag<1 || nlead<1) 
     error('Aim_eig: model must have at least one lag and one lead');
diff --git a/matlab/AIM/SPBuild_a.m b/matlab/AIM/SPBuild_a.m
index b2d8d9022546c0837d7923fb703f1a35fe42b98f..eb12473a8afef4a70b8088a7fc40233508253ed1 100644
--- a/matlab/AIM/SPBuild_a.m
+++ b/matlab/AIM/SPBuild_a.m
@@ -1,3 +1,4 @@
+function [a,ia,js] = SPBuild_a(h,qcols,neq)
 %  [a,ia,js] = SPBuild_a(h,qcols,neq)
 %
 %  Build the companion matrix, deleting inessential lags.
@@ -27,7 +28,6 @@
 % Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3,
 % pages 472-489
 
-function [a,ia,js] = SPBuild_a(h,qcols,neq)
 
 left  = 1:qcols;
 right = qcols+1:qcols+neq;
diff --git a/matlab/AIM/SPCopy_w.m b/matlab/AIM/SPCopy_w.m
index de39c0ec1bdf134eda9374a3af58121cea73c45e..714a1e27466116e2d35df8838c535cbd8e519009 100644
--- a/matlab/AIM/SPCopy_w.m
+++ b/matlab/AIM/SPCopy_w.m
@@ -1,3 +1,4 @@
+function  q = SPCopy_w(q,w,js,iq,qrows)
 % q = SPCopy_w(q,w,js,iq,qrows)
 %
 %  Copy the eigenvectors corresponding to the largest roots into the
@@ -27,7 +28,6 @@
 % Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3,
 % pages 472-489
 
-function  q = SPCopy_w(q,w,js,iq,qrows)
 
 if(iq < qrows)
    lastrows = iq+1:qrows;
diff --git a/matlab/AIM/SPEigensystem.m b/matlab/AIM/SPEigensystem.m
index 7a83c36cce684be5ffd8c02b29e50b6d1678c898..16855401a521704a22778f62c1dce3edcaa39f99 100644
--- a/matlab/AIM/SPEigensystem.m
+++ b/matlab/AIM/SPEigensystem.m
@@ -1,3 +1,4 @@
+function [w,rts,lgroots,flag_trouble] = SPEigensystem(a,uprbnd,rowsLeft)
 %  [w,rts,lgroots] = SPEigensystem(a,uprbnd)
 %
 %  Compute the roots and the left eigenvectors of the companion
@@ -29,7 +30,6 @@
 % Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3,
 % pages 472-489
 
-function [w,rts,lgroots,flag_trouble] = SPEigensystem(a,uprbnd,rowsLeft) 
 opts.disp=0; 
 % next block is commented out because eigs() intermitently returns different rts
 %try
diff --git a/matlab/AIM/SPExact_shift.m b/matlab/AIM/SPExact_shift.m
index 5f3700553a0dfbf387741590ff8c5bd51e221302..c9034e319bd3d309b4e49ebb53d6fa28a1e261d1 100644
--- a/matlab/AIM/SPExact_shift.m
+++ b/matlab/AIM/SPExact_shift.m
@@ -1,3 +1,4 @@
+function [h,q,iq,nexact] = SPExact_shift(h,q,iq,qrows,qcols,neq)
 % [h,q,iq,nexact] = exact_shift(h,q,iq,qrows,qcols,neq)
 %
 % Compute the exact shiftrights and store them in q.
@@ -26,7 +27,6 @@
 % Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3,
 % pages 472-489
 
-function [h,q,iq,nexact] = SPExact_shift(h,q,iq,qrows,qcols,neq)
 
 %hs=SPSparse(h);
 hs=sparse(h);
diff --git a/matlab/AIM/SPNumeric_shift.m b/matlab/AIM/SPNumeric_shift.m
index 38ee85759120a13d54354e50deab3aba89417440..cc1e1825f7588a1481d6fabe986c86b8d1b60616 100644
--- a/matlab/AIM/SPNumeric_shift.m
+++ b/matlab/AIM/SPNumeric_shift.m
@@ -1,3 +1,4 @@
+function [h,q,iq,nnumeric] = SPNumeric_shift(h,q,iq,qrows,qcols,neq,condn)
 %  [h,q,iq,nnumeric] = ...
 %             SPNumeric_shift(h,q,iq,qrows,qcols,neq,condn)
 %
@@ -27,7 +28,6 @@
 % Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3,
 % pages 472-489
 
-function [h,q,iq,nnumeric] = SPNumeric_shift(h,q,iq,qrows,qcols,neq,condn)
 
 nnumeric = 0;
 left     = 1:qcols;
diff --git a/matlab/AIM/SPObstruct.m b/matlab/AIM/SPObstruct.m
index 392781081bb80891d46e70e046487df94eb3485a..8620ca1b9b562ae859f342dfa093bc4337b29a68 100644
--- a/matlab/AIM/SPObstruct.m
+++ b/matlab/AIM/SPObstruct.m
@@ -1,3 +1,4 @@
+function scof = SPObstruct(cof,cofb,neq,nlag,nlead)
 % scof = SPObstruct(cof,cofb,neq,nlag,nlead)
 %
 % Construct the coefficients in the observable structure.
@@ -38,7 +39,6 @@
 % Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3,
 % pages 472-489
 
-function scof = SPObstruct(cof,cofb,neq,nlag,nlead)
 
 
 % Append the negative identity to cofb
diff --git a/matlab/AIM/SPReduced_form.m b/matlab/AIM/SPReduced_form.m
index d7ddd8a91b33a145a13ba06d98b5f3d9a096e551..3d5c8899078e52eb3f401904bad949351c48d73c 100644
--- a/matlab/AIM/SPReduced_form.m
+++ b/matlab/AIM/SPReduced_form.m
@@ -1,3 +1,4 @@
+function [nonsing,b] = SPReduced_form(q,qrows,qcols,bcols,neq,condn);
 % [nonsing,b] = SPReduced_form(q,qrows,qcols,bcols,neq,b,condn);
 %
 % Compute reduced-form coefficient matrix, b.
@@ -26,7 +27,6 @@
 % Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3,
 % pages 472-489
 
-function [nonsing,b] = SPReduced_form(q,qrows,qcols,bcols,neq,condn);
 b=[];
 %qs=SPSparse(q);
 qs=sparse(q);