Resistor mesh: Difference between revisions

Content added Content deleted
(Added Phix)
Line 1,443: Line 1,443:
{{out}}
{{out}}
<pre>1.60899124172989</pre>
<pre>1.60899124172989</pre>

=={{header|Phix}}==
{{trans|BBC_BASIC}}
uses inverse() from [[Gauss-Jordan_matrix_inversion#Phix]]
and matrix_mul() from [[Matrix_multiplication#Phix]]
<lang Phix>function resistormesh(integer ni, nj, ai, aj, bi, bj)
integer n = ni*nj, k, c
sequence A = repeat(repeat(0,n),n),
B = repeat({0},n)
for i=1 to ni do
for j=1 to nj do
k = (i-1)*nj + j--1
if i=ai and j=aj then
A[k,k] = 1
else
c = 0
if i<ni then c += 1; A[k,k+nj] = -1 end if
if i>1 then c += 1; A[k,k-nj] = -1 end if
if j<nj then c += 1; A[k,k+1] = -1 end if
if j>1 then c += 1; A[k,k-1] = -1 end if
A[k,k] = c
end if
end for
end for
k = (bi-1)*nj +bj
B[k,1] = 1
A = inverse(A)
B = matrix_mul(A,B)
return B[k,1]
end function

printf(1,"Resistance = %.13f ohms\n",resistormesh(10, 10, 2, 2, 8, 7))</lang>
{{out}}
<pre>
Resistance = 1.6089912417307 ohms
</pre>


=={{header|Python}}==
=={{header|Python}}==