Jump to content

Display a linear combination: Difference between revisions

no edit summary
(Added Julia language)
No edit summary
Line 383:
-1, -2, 0, -3 ──► -e(1) - 2*e(2) - 3*e(4)
-1 ──► -e(1)
</pre>
 
=={{header|Ring}}==
<lang ring>
scalars = [[1, 2, 3], [0, 1, 2, 3], [1, 0, 3, 4], [1, 2, 0], [0, 0, 0], [0], [1, 1, 1], [-1, -1, -1], [-1, -2, 0, -3], [-1]]
for n=1 to len(scalars)
str = ""
for m=1 to len(scalars[n])
scalar = scalars[n] [m]
if scalar != "0"
if scalar = 1
str = str + "+e" + m
elseif scalar = -1
str = str + "" + "-e" + m
else
if scalar > 0
str = str + char(43) + scalar + "*e" + m
else
str = str + "" + scalar + "*e" + m
ok
ok
ok
next
if str = ""
str = "0"
ok
if left(str, 1) = "+"
str = right(str, len(str)-1)
ok
see str + nl
next
</lang>
Output:
<pre>
e1+2*e2+3*e3
e2+2*e3+3*e4
e1+3*e3+4*e4
e1+2*e2
0
0
e1+e2+e3
-e1-e2-e3
-e1-2*e2-3*e4
-e1
</pre>
 
2,468

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.