Anonymous user
Display a linear combination: Difference between revisions
m
→{{header|REXX}}: added whitespace, added a template for the output.
m (→{{header|REXX}}: added whitespace, added a template for the output.) |
|||
Line 881:
=={{header|REXX}}==
<lang rexx>/*REXX program displays a finite liner combination in an infinite vector basis. */
@.=.; @.1 = ' 1, 2, 3 '
@.2 = ' 0, 1, 2, 3 '
@.3 = ' 1, 0, 3, 4 '
@.4 = ' 1, 2, 0 '
@.5 = ' 0, 0, 0 '
@.6 = 0
@.7 = ' 1, 1, 1 '
@.8 = ' -1, -1, -1 '
@.9 = ' -1, -2, 0, -3 '
@.10 = -1
do j=1 while @.j\==.; n=
y= space( translate(@.j, ,',') )
$= /*nullify output (liner combination).*/
do k=1 for words(y); #= word(y, k)
if #=0 then iterate; a= abs(# / 1)
s= '+ ' ;
n= n + 1;
if a\==1 then s= s || a'*'
$= $ s'e('k")"
end /*k*/
$= strip( strip($), 'L', "+")
if $=='' then $=
say right( space(@.j), 20) ' ──► ' strip($) /*align the output for presentation. */
▲ /*stick a fork in it, we're all done. */</lang>
▲'''output''' when using the default inputs:
<pre>
1, 2, 3 ──► e(1) + 2*e(2) + 3*e(3)
|