Message Boards Message Boards

0
|
7727 Views
|
7 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Resistor simulation

Posted 4 years ago

How can we use the software Mathematica to simulate and calculate the equivalent resistance between node A and node B in the 7x7 grid of resistors?

enter image description here

POSTED BY: Thang Nguyen
7 Replies

This problem is potentially dangerous - I do hope that everyone is still well!

POSTED BY: Henrik Schachner
Posted 4 years ago

Thank you so much!

POSTED BY: Thang Nguyen

With our getting into the correctness of the computation itself (I didn't check that) there is an obvious syntax error You forgot using a Module or a Block

So the code should look like

gridresistor[p_, q_, ai_, aj_, bi_, bj_] := 
  Module [{A, B, k, c, V}, A = ConstantArray[0, {p*q, p*q}];
...
]

Yes you are right.Thanks.

POSTED BY: Mariusz Iwaniuk

Maybe this and this helps.

EDITED:

Using code from links:

And Assuming:Grid where each edge depicts a resistor between its incident nodes (all resistance values are assumed to be 1Ω

gridresistor[p_, q_, ai_, aj_, bi_, bj_] := 
   [{A, B, k, c, V}, A = ConstantArray[0, {p*q, p*q}];
  Do[k = (i - 1) q + j;
   If[{i, j} == {ai, aj}, A[[k, k]] = 1, c = 0;
    If[1 <= i + 1 <= p && 1 <= j <= q, c++; A[[k, k + q]] = -1];
    If[1 <= i - 1 <= p && 1 <= j <= q, c++; A[[k, k - q]] = -1];
    If[1 <= i <= p && 1 <= j + 1 <= q, c++; A[[k, k + 1]] = -1];
    If[1 <= i <= p && 1 <= j - 1 <= q, c++; A[[k, k - 1]] = -1];
    A[[k, k]] = c], {i, p}, {j, q}];
  B = SparseArray[(k = (bi - 1) q + bj) -> 1, p*q];
  LinearSolve[A, B][[k]]];

  g1 = 7; g2 = 7;(*Grid 7 x 7*)
  Ax = 4; Ay = 5;(*Node A*)
  Bx = 5; By = 4;(*Node B*)

  N[gridresistor[g1, g2, Ax, Ay, Bx, By]]
  (*0.660852*)
POSTED BY: Mariusz Iwaniuk
Posted 4 years ago

I want to ask that why we have that loop in the code:

 Do[k = (i - 1) q + j;
   If[{i, j} == {ai, aj}, A[[k, k]] = 1, c = 0;
    If[1 <= i + 1 <= p && 1 <= j <= q, c++; A[[k, k + q]] = -1];
    If[1 <= i - 1 <= p && 1 <= j <= q, c++; A[[k, k - q]] = -1];
    If[1 <= i <= p && 1 <= j + 1 <= q, c++; A[[k, k + 1]] = -1];
    If[1 <= i <= p && 1 <= j - 1 <= q, c++; A[[k, k - 1]] = -1];
    A[[k, k]] = c], {i, p}, {j, q}];

And why A[[k, k + q]], A[[k, k - q]], A[[k, k + 1]], A[[k, k - 1]] is equal to -1?

POSTED BY: Thang Nguyen

My coding in Wolfram language are quite low so I can't help you.

POSTED BY: Mariusz Iwaniuk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract