Anonymous user
LU decomposition: Difference between revisions
m
→{{header|REXX}}: changed/added comments and whitespace, changed indentations.
(→{{header|Java}}: added Java) |
m (→{{header|REXX}}: changed/added comments and whitespace, changed indentations.) |
||
Line 2,557:
=={{header|REXX}}==
<lang rexx>/*REXX
#=0; P.=0; PA.=0; L.=0; U.=0
parse arg x /*
call makeMat /*make the A matrix from the numbers.*/
call showMat 'A', N /*display the A matrix. */
call manPmat /*manufacture P (permutation). */
call showMat 'P', N /*display the P matrix. */
call multMat /*multiply the A and P matrices. */
call showMat 'PA', N /*display the PA matrix. */
do y=1 for N; call manUmat y /*manufacture U matrix, parts. */
call manLmat y /*manufacture L matrix, parts. */
end
call showMat 'L', N /*display the L matrix. */
call showMat 'U', N /*display the U matrix. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
er: say; say '***error!***'; say; say arg(1); say; exit 13
/*──────────────────────────────────────────────────────────────────────────────────────*/
makeMat: ?=words(x);
if N**2\==? then call er 'not correct number of elements entered: ' ?
do r=1 for N /*build the "A" matrix from input*/▼
do
if \datatype(_,'N') then call er "element isn't numeric: " _
end /*c*/▼
end /*r*/
return▼
/*──────────────────────────────────────────────────────────────────────────────────────*/
manLmat: arg ? /*manufacture L (lower) matrix.*/▼
manLmat: parse arg ?
end /*r*/
return▼
/*──────────────────────────────────────────────────────────────────────────────────────*/
manPmat: c=N; do r=N by
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
manUmat: arg ? /*manufacture U (upper) matrix.*/▼
manUmat: parse arg ?
do
do k=1 for r-1; _=_-U.
▲ return
/*──────────────────────────────────────────────────────────────────────────────────────*/
multMat: do
▲ return
/*──────────────────────────────────────────────────────────────────────────────────────*/
do r =1 for rows▼
showMat: parse arg mat,rows,cols; w=0;
▲ end
do c=1 for cols; w=max(w, length( value( mat'.'r"."c ) ) )
say center(mat 'matrix',cols*(w+1)+7,"─")▼
▲ say center(mat 'matrix',cols*(w+1)+7,"─")
▲ end
do r=1 for rows; _=
return</lang>▼
do c=1 for cols; _=_ right(value(mat'.'r'.'c),w+1); end /*c*/
{{out}} when using the input of: <tt> 1 3 5 2 4 7 1 1 0 </tt>▼
say _
end /*r*/
▲ return</lang>
▲
<pre>
──A matrix───
Line 2,653 ⟶ 2,657:
0 0 -2
</pre>
<pre>
─────A matrix──────
|