September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
20
Task/Resistor-mesh/Zkl/resistor-mesh-1.zkl
Normal file
20
Task/Resistor-mesh/Zkl/resistor-mesh-1.zkl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
var [const] GSL=Import("zklGSL"); // libGSL (GNU Scientific Library)
|
||||
fcn onGrid(i,j,p,q){ ((0<=i<p) and (0<=j<q)) }
|
||||
fcn gridResistor(p,q, ai,aj, bi,bj){
|
||||
n,A := p*q, GSL.Matrix(n,n); // zero filled
|
||||
foreach i,j in (p,q){
|
||||
k:=i*q + j;
|
||||
if(i==ai and j==aj) A[k,k]=1;
|
||||
else{
|
||||
c:=0;
|
||||
if(onGrid(i+1,j, p,q)){ c+=1; A[k, k+q]=-1 }
|
||||
if(onGrid(i-1,j, p,q)){ c+=1; A[k, k-q]=-1 }
|
||||
if(onGrid(i, j+1, p,q)){ c+=1; A[k, k+1]=-1 }
|
||||
if(onGrid(i, j-1, p,q)){ c+=1; A[k, k-1]=-1 }
|
||||
A[k,k]=c;
|
||||
}
|
||||
}
|
||||
b:=GSL.Vector(n); // zero filled
|
||||
b[k:=bi*q + bj]=1;
|
||||
A.AxEQb(b)[k];
|
||||
}
|
||||
1
Task/Resistor-mesh/Zkl/resistor-mesh-2.zkl
Normal file
1
Task/Resistor-mesh/Zkl/resistor-mesh-2.zkl
Normal file
|
|
@ -0,0 +1 @@
|
|||
gridResistor(10,10, 1,1, 7,6).println();
|
||||
Loading…
Add table
Add a link
Reference in a new issue