Resistor mesh: Difference between revisions

Content added Content deleted
Line 1,271: Line 1,271:


=={{header|Mathematica}}==
=={{header|Mathematica}}==
Use <b>KirchhoffMatrix</b>, <b>PseudoInverse</b>, and <b>GridGraph</b> to compute the resistance between <em>any</em> two points.
{{works with|Mathematica|8.0}}
{{works with|Mathematica|8.0}}

<lang mathematica>
Use <b>KirchhoffMatrix</b>, <b>PseudoInverse</b>, and <b>GridGraph</b> to compute the resistance between <em>any</em> two points.
resistanceGraph[g_, prec_:$MachinePrecision]:=

<lang mathematica>resistanceGraph[g_, prec_:$MachinePrecision]:=
With[{M = PseudoInverse[N[ KirchhoffMatrix[g], prec]]},
With[{M = PseudoInverse[N[ KirchhoffMatrix[g], prec]]},
Outer[Plus, Diagonal[M], Diagonal[M]] - M - Transpose[M]
Outer[Plus, Diagonal[M], Diagonal[M]] - M - Transpose[M]