Anonymous user
Resistor mesh: Difference between revisions
m
→{{header|REXX}}: changed wording of the output, allowed specification of decimal digits used; adding verbiage to the REXX section header, optimized the inner DO loop.
m (→{{header|REXX}}: added/changed comments and whitespace, changed indentations, added wording to the REXX section header about precision and execution times.) |
m (→{{header|REXX}}: changed wording of the output, allowed specification of decimal digits used; adding verbiage to the REXX section header, optimized the inner DO loop.) |
||
Line 1,245:
=={{header|REXX}}==
{{trans|Ada}}
This version allows specification of the
Dropping the decimal digits precision ('''numeric digits''') to '''10''' will make the execution '''3''' times faster.
<lang rexx>/*REXX program calculates the resistance between any two points on a resister grid.*/
minVal = (1'e-' || (digits()*2)) / 1 /*calculate the threshold minimul value*/▼
if 2=='f2'x then ohms = "ohms" /*EBCDIC machine? Then use 'ohms'. */
else ohms = "Ω" /* ASCII " " " Greek Ω.*/
parse arg
if high=='' | high=="," then high=10 /*Not specified? Then use the default.*/
if wide=='' | wide=="," then wide=10 /* " " " " " " */
Line 1,260 ⟶ 1,258:
if Brow=='' | Brow=="," then Brow= 7 /* " " " " " " */
if Bcol=='' | Bcol=="," then Bcol= 8 /* " " " " " " */
say ' minimum value is ' format(minVal,,,,0) " using " digs ' decimal digits'; say
say ' resistor mesh size is: ' wide "wide, " high 'high' ; say
say ' point A is at (row,col): ' Arow"," Acol
say ' point B is at (row,col): ' Brow"," Bcol
@.=0; cell.=1
do until $
@.Arow.Acol
@.Brow.Bcol
$=0
do i=1 for high; im=i
do j=1 for wide;
if i\==1 then do; v=v + @.im.j;
if j\==1 then do; jm=j-1; v=v + @.i.jm;
if i<high then do; v=v + @.ip.j;
if j<wide then do; jp=j+1; v=v + @.i.jp;
v=@.i.j - v/n; #.i.j=v;
end /*j*/
end /*i*/
do r=1 for High
do c=1 for Wide;
end /*c*/
end /*r*/
end /*until*/
say
Acur
Bcur
say ' resistance between point A and point B is: '
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
sides: parse arg row,col; z=0; if row\==1 & row\==high then z=z
if col\==1 & col\==wide then z=z
return z</lang>
{{out|output|text= when using the default inputs:}}
<pre>
minimum value
resistor mesh size is
point A is at (row,col): 2, 2
|