Resistor mesh: Difference between revisions

m
→‎{{header|REXX}}: made some cosmetic changes.
m (→‎{{header|Sidef}}: updated code)
m (→‎{{header|REXX}}: made some cosmetic changes.)
Line 1,179:
numeric digits 20 /*use moderate decimal digs (precision)*/
minVal = (1'e-' || (digits()*2)) / 1 /*calculate the threshold minimul value*/
if 12=='f1f2'x then ohms = 'ohms' /*EBCDIC machine? Then use 'ohms'. */
else ohms = 'ea'x /* ASCII " " " Greek Ω.*/
parse arg high wide Arow Acol Brow Bcol . /*obtain optional arguments from the CL*/
Line 1,193:
say ' point B is at (row,col): ' Brow"," Bcol
@.=0; cell.=1
do until $ <= minVal; v = 0
@.Arow.Acol = +1 ; cell.Arow.Acol = 0
@.Brow.Bcol = -1 ; cell.Brow.Bcol = 0
$=0
do i=1 for high; im=i - 1; ip=i + 1
do j=1 for wide; jm=j - 1; jp=j + 1; n=0; v=0
if i\==1 then do; v=v + @.im.j; n=n + 1; end
if j\==1 then do; v=v + @.i.jm; n=n + 1; end
if i<high then do; v=v + @.ip.j; n=n + 1; end
if j<wide then do; v=v + @.i.jp; n=n + 1; end
v=@.i.j - v/n; #.i.j=v; if cell.i.j then $=$ + v*v
end /*j*/
end /*i*/
Line 1,212:
end /*until*/
say
Acur = #.Arow.Acol * sides(Arow, Acol)
Bcur = #.Brow.Bcol * sides(Brow, Bcol)
say ' resistance between point A and point B is: ' 4/(Acur-Bcur) ohms
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 + 2
else z=z + 1
if col\==1 & col\==wide then z=z + 2
else z=z + 1
return z</lang>
{{out|output|text=&nbsp; when using the default inputs:}}