## LU Decompositions

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

CharlieEVIEWS
Posts: 202
Joined: Tue Jul 17, 2012 9:47 am

### LU Decompositions

Here's an early version of an attempted LU decomposition (partial pivot method). It's not overly efficient but I will possibly modify it to also work for matrices where the leading diagonal isn't zero at some point soon, and post below.

Code: Select all

`!n=@rows(A)matrix L = @identity(!n)matrix P=  @identity(!n)matrix U=Afor !k=1 to !n-1   vector temp = @subextract(U,!k,!k,!n,!k)   !pivot=@max(@abs(temp))   for !j = 1 to @rows(temp)      if @abs(temp(!j))=!pivot then         !ind=!j+!k-1      '   !j=!n+1      endif   next   d temp   vector temp_k = @subextract(U,!k,!k,!k,!n)   vector temp_ind = @subextract(U,!ind,!k,!ind,!n)   matplace(U,temp_k,!ind,!k)   matplace(U,temp_ind,!k,!k)   d temp_k temp_ind   vector temp_k = @subextract(L,!k,1,!k,!k-1)   vector temp_ind = @subextract(L,!ind,1,!ind,!k-1)   matplace(L, temp_k,!ind,1)   matplace(L, temp_ind,!k,1)   d temp_k temp_ind   vector temp_k = @rowextract(P,!k)   vector temp_ind = @rowextract(P,!ind)   matplace(P,temp_k,!ind,1)   matplace(P,temp_ind,!k,1)   d temp_k temp_ind   for !j= !k+1 to !n      L(!j,!k)=U(!j,!k)/U(!k,!k)      matplace(U,@subextract(U,!j,!k,!j,!n)-L(!j,!k)*@subextract(U,!k,!k,!k,!n),!j,!k)   nextnext`