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