Cholesky decomposition: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed whitespace and comments, made other cosmetic improvements.) |
|||
Line 1,996: | Line 1,996: | ||
If trailing zeroes are wanted after the decimal point for values of zero (0), the <big>'''/1'''</big> (division by one performs |
If trailing zeroes are wanted after the decimal point for values of zero (0), the <big>'''/1'''</big> (division by one performs |
||
<br>REXX number normalization) can be removed from the line (number 73) which contains the source statement: |
<br>REXX number normalization) can be removed from the line (number 73) which contains the source statement: |
||
<br> <code> |
<br> <code> z=z right( format(@.row.col,, dPlaces) /1, width) </code> |
||
<lang rexx>/*REXX program |
<lang rexx>/*REXX program performs the Cholesky decomposition on a square matrix. */ |
||
⚫ | |||
'15 18 0' , |
|||
'-5 0 11' |
|||
call Cholesky niner |
|||
hexer = 18 22 54 42, /*define a 4x4 matrix. */ |
|||
22 70 86 62, |
|||
54 86 174 134, |
|||
42 62 134 106 |
|||
call Cholesky hexer |
|||
exit /*stick a fork in it, we're all done. */ |
|||
/*──────────────────────────────────Cholesky subroutine───────────────────────*/ |
|||
⚫ | |||
⚫ | |||
/*─────────────────────────────────────Cholesky subroutine──────────────*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
if r=c then !.r.r=sqrt(!.r.r-$) |
|||
else !.r.c=1/!.c.c*(@.r.c-$) |
|||
end /*c*/ |
|||
end /*r*/ |
|||
⚫ | |||
⚫ | |||
if row=col then $.row.row=sqrt($.row.row-s) |
|||
else $.row.col=1/$.col.col*(@.row.col-s) |
|||
end /*col*/ |
|||
end /*row*/ |
|||
⚫ | |||
return |
return |
||
/*─────────────────────────────────ERR subroutine─────────────────────────────*/ |
|||
/*─────────────────────────────────────TELL subroutine───&find the order*/ |
|||
⚫ | |||
tell: parse arg hdr,x,y,sep; #=0; if sep=='' then sep='═' |
|||
/*─────────────────────────────────TELL subroutine────────────────────────────*/ |
|||
⚫ | |||
tell: parse arg hdr,x,y,sep; #=0; if sep=='' then sep='═' |
|||
⚫ | |||
width =10 /*width of field used to display elements*/ |
|||
if y=='' then |
if y=='' then !.=0 |
||
⚫ | |||
else do row=1 for ord; do col=1 for ord; x=x !.row.col; end; end |
|||
⚫ | |||
⚫ | |||
end /*col*/ |
|||
w=words(x) |
w=words(x) |
||
⚫ | |||
say |
|||
⚫ | |||
⚫ | |||
end /*order*/ |
|||
⚫ | |||
say |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
@.row.col=word(x,#) |
|||
if col<=row then !.row.col=@.row.col |
|||
z=z right( format(@.row.col,, dPlaces) / 1, width) |
|||
end /*col*/ |
|||
⚫ | |||
aLine=aLine right( format(@.row.col,, decPlaces) /1, width) |
|||
end /*col*/ |
|||
⚫ | |||
end /*row*/ |
end /*row*/ |
||
return |
return |
||
/*─────────────────────────────────SQRT subroutine────────────────────────────*/ |
|||
/*─────────────────────────────────────SQRT subroutine──────────────────*/ |
|||
sqrt: procedure; |
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); p=d+d%4+2; m.=11 |
||
numeric digits |
numeric form; numeric digits m.; parse value format(x,2,1,,0)'E0' with g 'E' _ . |
||
g=g*.5'E'_%2; do j=0 while p>9; m.j=p; p=p%2+1; end |
|||
do k=j+5 to 0 by -1; if m.k>11 then numeric digits m.k; g=.5*(g+x/g); end |
|||
numeric digits d; return g/1</lang> |
|||
.sqrtGuess: if x<0 then call err 'SQRT of negative #'; numeric form |
|||
m.=11; p=d+d%4+2; parse value format(x,2,1,,0) 'E0' with g 'E' _ . |
|||
return g*.5'E'_%2 |
|||
/*─────────────────────────────────────ERR subroutine───────────────────*/ |
|||
⚫ | |||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,076: | Line 2,060: | ||
3 3 0 |
3 3 0 |
||
-1 1 3 |
-1 1 3 |
||
════════════════input array═════════════════ |
════════════════input array═════════════════ |