# Solving simultaneous equations
## Introduction

The word "simultaneous" implies that two or more equations exist in the same context at the same time.
For example:
$3x+2y-13=0\ \dots \ (1)$
$2x-y-4=0\ \dots \ (2)$
Equations $(1)$ and $(2)$ are 2 simultaneous equations.
When we see two simultaneous equations, it's natural to ask the question: What are the values of $x$ and $y$ that satisfy both equations $(1)$ and $(2)$?
To calculate $(x,y)$ common to both $(1)$ and $(2)$:
$(2)*2\ \dots \ 4x-2y-8=0\ \dots \ (3)$
$(3)+(1)\ \dots \ 7x-21=0;\ x=3.$
Substitute $3$ for $x$ in $(2):\ 2(3)-y-4=0;\ y=2.$
The values $(x,y)=(3,2)$ satisfy both equations $(1)$ and $(2).$
In cartesian coordinate geometry of 2 dimensions, point $(3,2)$ is the point of intersection of two lines $(1)$ and $(2).$ See Figure 1 below.
If the 2 lines are parallel, there is no point of intersection. See Figure 2 below.
The trivial solution $(0,0)$ is a valid solution. See Figure 3 below.
* Figure 1. 2 lines that intersect at point (3,2).
* Figure 2. When 2 lines are parallel, there is no point of intersection.
* Figure 3. The trivial solution x=y=0 is a valid solution.
The information contained in equations $(1)$ and $(2)$ may constitute a matrix:
In fact, in the python programming language, the following statement is valid code:
For there to be a point of intersection, data must be valid.
Here are examples of invalid data:
The matrix above with name "data" is described as matrix "2 by 3," meaning that it contains 2 rows with 3 columns or 3 members per row.

## Solving 2 by 3

Below is python code containing function solve2by3 (input). The function accepts as input a matrix like data above.
After the code are examples of invocation with both good data and bad data.
Invocation with good data:
* output = solve2by3([
* [3, 2, -13],
* [2, -1, -4]
* print (output)
* (3.0, 2.0)
Invocation with bad or invalid data:
* output = solve2by3([
* [3, 2, -13], # Both lines are parallel.
* [6, 4, -5] # See Figure 2 above.
* print (output)
* solve2by3 : parallel input.
* input =
* [3, 2, -13]
* [6, 4, -5]
* None
* output = solve2by3([
* [3, 2, -13, 7], # Input matrix not exactly 2 by 3.
* [6, 4, -5]
* print (output)
* solve2by3 :
* error detected in processing.
* (<class 'ValueError'>, ValueError('too many values to unpack (expected 3)',))
* input =
* [3, 2, -13, 7]
* [6, 4, -5]
* None
* output = solve2by3([
* [3, 0, 2],
* [6, 0, 4]
* print (output)
* solve2by3 : empty column in input.
* input =
* [3, 0, 2]
* [6, 0, 4]
* None

### Reversing the process
#### Linear Function

Examples above calculate the point of intersection of 2 lines.
An example of reversing the process is this task:
Given two points $(x_{1},y_{1}),(x_{2},y_{2})$ calculate equation of line containing these 2 points.
Equation of line is of format $Ax+By+C=0,$
For example: $3x+2y+10=0\ \dots \ (1).$
Equation $(1)$ can be expressed as $6x+4y+20=0$ or $-9x-6y-30=0.$
Also, there appear to be 3 unknowns, but only two sets of values are required to define the line.
Assume $C=1$ and the 2 relevant equations are:
$Ax_{1}+By_{1}+1=0$
$Ax_{2}+By_{2}+1=0$
To solve for $A,B:$
$x_{1}A+y_{1}B+1=0$
$x_{2}A+y_{2}B+1=0$
Suppose the line is defined by points $(3,1),(-5,4):$
Desired equation is: $-0.17647058823529413\cdot x-0.47058823529411764\cdot y+1=0\ \dots \ (2).$
To improve appearance of $(2):$
Let $A,B=3,8$ and check:
Desired equation $(2)$ becomes $3x+8y-17=0\ \dots \ (3).$

#### Wrong assumptions

Sometimes you create a matrix that seems correct, but it fails to produce a result. Here is such an example:
What is equation of line defined by points $(3,2),(6,4)?$
As above assume that $C=1.$
This assumption failed:
Assume that $A=1.$
Equation of line is: $1\cdot x+(-1.5)\cdot y+0=0$ or $2x-3y=0$
This line includes the origin. Therefore constant $C$ cannot be non-zero.
Generally:
* Without rotation, $A,B={\text{result}}$ and $C=1.$
* With rotation left by one column, $B,C={\text{result}}$ and $A=1.$
In this case:
For example of big matrix that failed the first time, but was successful the second time, see cubic resistive network below.

## Solving 3 by 4

Below is python code containing function solve3by4 (input). The function accepts as input a 3 by 4 matrix like that described in the code comments.
In 3d coordinate geometry the equations (1), (2), (3) are the equations of 3 planes and the solution of the system is the point of intersection of the 3 planes.
Given 3 random planes, there are 2 conditions that do not produce a point of intersection:
* If 2 of the planes are parallel. See Figure 1 below.
* If the 3 planes form a "tent" or "delta." See Figure 2, 3 or 4 below. A special case of this condition occurs when size of "tent" is zero, in which case all three planes intersect on a common line and there is an infinite number of solutions. See Figure 5 below.
The trivial solution $(0,0,0)$ is valid. See Figure 6 below.
* Figure 1. When 2 planes are parallel, there is no point of intersection.
* Figure 2. Triangular tube, 3 planes that never intersect.
* Figure 3. 3 planes that form a "tent," view 1. There is no point of intersection.
* Figure 4. 3 planes that form a "tent," view 2. There is no point of intersection.
* Figure 5. 3 planes that intersect on a common line. Points $(6,6,1),$ $(7,7,4),$ $(8,8,7)$ are on this line and are common to all 3 planes.
* Figure 6. 3 planes that intersect at origin (0, 0, 0).
Below are examples of invocation with both good data and bad data.
Invocation with good data:
* output = solve3by4([
* [2, -1, 3, -17],
* [1, 3, 2, -25] ,
* [3, 2, -1, -12] ,
* print (output)
* (3.0, 4.0, 5.0)
* output = solve3by4([
* [12, -12, -5, -24],
* [-6, 15, 8, 12] ,
* [ 0, 10, 3, 0] ,
* print (output)
* (2.0, 0.0, -0.0)
Invocation with bad or invalid data:
* output = solve3by4([
* [20, 16, 2, 17],
* [-77, -27, -25, -24],
* [81, 45, 18, 43]
* print (output)
* solve2by3 : parallel input.
* input =
* (-692, 346, -829)
* (396, -198, 517)
* checkDirectionNumbers : 3 rows form a tent.
* input of solve3by4 =
* [20, 16, 2, 17]
* [-77, -27, -25, -24]
* [81, 45, 18, 43]
* None
* output = solve3by4([
* [-34, -6, 34, -32],
* [82, 14, -82, 72],
* [-59, -45, 59, -88]
* print (output)
* solve2by3 : empty column in input.
* input =
* (-16, 0, -176)
* (-1176, 0, -1104)
* checkDirectionNumbers : 3 rows form a tent.
* input of solve3by4 =
* [-34, -6, 34, -32]
* [82, 14, -82, 72]
* [-59, -45, 59, -88]
* None
* output = solve3by4([
* [34, -5, -21, 30],
* [-54, -33, 63, 62],
* [18, 11, -21, 38]
* print (output)
* solve2by3 : parallel input.
* input =
* (1392, -1008, -3728)
* (-464, 336, -752)
* checkDirectionNumbers : 2 rows parallel, 2 and 3.
* input of solve3by4 =
* [34, -5, -21, 30]
* [-54, -33, 63, 62]
* [18, 11, -21, 38]
* None
* output = solve3by4([
* [20, 16, 2, 17],
* [-77, -27, '-25', -24],
* [81, 45, 18, 43]
* print (output)
* solve3by4 :
* error detected in processing.
* (<class 'TypeError'>, TypeError("unsupported operand type(s) for -: 'int' and 'str'",))
* input of solve3by4 =
* [20, 16, 2, 17]
* [-77, -27, '-25', -24]
* [81, 45, 18, 43]
* None

### Reversing the Process
#### Quadratic function

A quadratic function $y=f(x)=Ax^{2}+Bx+C$ is defined by 3 points: $(-2,9.0),(5,4.8),(10,13.8).$
What is $f(x)?$
$y=Ax^{2}+Bx+C$
$A,B,C$ are 3 unknowns.
$x^{2}(A)+x(B)+1(C)-y=0$
$y=f(x)=0.2x^{2}-1.2x+5.8$

#### Wrong assumptions

In 3 dimensions a plane ($Ax+By+Cz+D=0$) is defined by 3 points: $(5,3,-2),(-1,12,-8),(37,15,-10).$
What is equation of plane?
$Ax+By+Cz+D=0$
$xA+yB+zC+D=0$
Assume that $D=1.$
$xA+yB+zC+1=0$
Input was invalid. Rotate input left and try again.
Input was invalid. Rotate input left and try again.
Without rotation: $A,B,C={\text{result}}$ and $D=1.$
With rotation left: $B,C,D={\text{result}}$ and $A=1.$
With another rotation left: $C,D,A={\text{result}}$ and $B=1.$
Equation of plane is: $0x+1y+1.5z+0=0$ or $2y+3z=0$

##### A better method

* There are four unknown values: $A,B,C,D.$
* Create matrix 4 by 5:
* # python code.
* pt1 = x1,y1,z1 = (5, 3, -2)
* pt2 = x2,y2,z2 = (-1, 12, -8)
* pt3 = x3,y3,z3 = (37, 15, -10)
* input =
* for (x_,y_,z_) in (pt1,pt2,pt3) :
* x,y,z = [ dD(v) for v in (x_,y_,z_) ]
* input += [ [ x,y,z,1,0 ] ]
* # For valid plane at least one of A,B,C must be non-zero.
* # For last condition let A + B + C = 5.
* input += [ [ 1,1,1,0,-5 ] ]
* A,B,C,D = solveMbyN(input)
* print (input)
* print ( '()x + ()y + ()z + () = 0'.format(A,B,C,D) )
* [[ 5, 3, -2, 1, 0], # 5A + 3B - 2C + 1D + 0 = 0
* [-1, 12, -8, 1, 0], # -1A + 12B - 8C + 1D + 0 = 0
* [37, 15, -10, 1, 0], # 37A + 15B - 10C + 1D + 0 = 0
* [ 1, 1, 1, 0, -5]] # 1A + 1B + 1C + 0D - 5 = 0
* (0)x + (2)y + (3)z + (0) = 0
* Equation of plane is: $2y+3z=0.$

## Solving M by (M+1)

Below is python code containing function solveMbyN (input). The function accepts as input a 4 by 5 matrix (or greater) like that described in the code comments.
This function is recursive, calling itself with M being reduced by 1 with each recursive invocation until the matrix is size 3 by 4 in which case function solve3by4 is called.
Below are examples of invocation with both good data and bad data.
Invocation with good data:
* L1 = [
* [Decimal('-870442133162'), Decimal('239132906684'), Decimal('397660499756'), Decimal('788825405004'), Decimal('156830886652'), Decimal('-87096140169')],
* [Decimal('-112130420352'), Decimal('-93605595828'), Decimal('-185262083472'), Decimal('-93369903383'), Decimal('-497973505065'), Decimal('-766710012513')],
* [Decimal('-142983492168'), Decimal('619713461197'), Decimal('-608752759383'), Decimal('-448477443042'), Decimal('-281161661751'), Decimal('-799463977245')],
* [Decimal('572854919541'), Decimal('-148673693908'), Decimal('341291756040'), Decimal('362403188059'), Decimal('-202136092949'), Decimal('-429932229578')],
* [Decimal('157632861972'), Decimal('330790263276'), Decimal('-836474627955'), Decimal('644295395386'), Decimal('-595590967129'), Decimal('-392835045727')]
* output = solveMbyN(L1)
* print (output)
* The following results were produced with decimal precision set at 50:
* Decimal('-0.06331410760212760088313271882866553044211194694576'), Decimal('1.0969089506763419155148060427588009931309074487534'), Decimal('1.0837038580207682607126722016017867670831200359767'), Decimal('-0.42989566124678842791674322699930461340596671792215'), Decimal('-2.0541601084281682582146753421426610779297051535362')
Invocation with bad or invalid data:
* output = solveMbyN([
* [-4.0, -6.0, 3.0, -4.0, -8.0, -8.0],
* [1.0, 0.0, 2.0, 5.0, 1.0, 7.0],
* [9.0, -3.0, -8.0, 4.0, 7.0, -5.0],
* [1.0, -9.0, 5.0, -2.0, 5.0, -2.0],
* [1.0, -3.0, -6.0, -3.0, -6.0, 6.0]
* print (output)
* solve2by3 : parallel input.
* input =
* (-181440.0, 181440.0, -101088.0)
* (90720.0, -90720.0, 406944.0)
* checkDirectionNumbers : 3 rows form a tent.
* input of solve3by4 =
* [-756.0, -1176.0, 0.0, -1872.0]
* [-324.0, -744.0, 240.0, -936.0]
* [-324.0, -384.0, -120.0, -264.0]
* input of solveMbyN with 4 rows =
* [-6.0, 11.0, 16.0, -4.0, 20.0]
* [-66.0, -5.0, -20.0, -44.0, -92.0]
* [-42.0, 23.0, -12.0, 12.0, -16.0]
* [-18.0, -21.0, -16.0, -32.0, 16.0]
* input of solveMbyN with 5 rows =
* [-4.0, -6.0, 3.0, -4.0, -8.0, -8.0]
* [1.0, 0.0, 2.0, 5.0, 1.0, 7.0]
* [9.0, -3.0, -8.0, 4.0, 7.0, -5.0]
* [1.0, -9.0, 5.0, -2.0, 5.0, -2.0]
* [1.0, -3.0, -6.0, -3.0, -6.0, 6.0]
* None
* output = solveMbyN([
* [Decimal('-4'), Decimal('-6'), Decimal('3'), Decimal('-4'), Decimal('-8'), Decimal('-8')],
* [Decimal('1'), Decimal('0'), Decimal('2'), Decimal('5'), Decimal('1'), Decimal('7')],
* [Decimal('9'), Decimal('-3'), Decimal('-8'), Decimal('4'), Decimal('7'), Decimal('-5')],
* [Decimal('1'), Decimal('-9'), Decimal('5'), Decimal('-2'), Decimal('5'), Decimal('-2')],
* [Decimal('1'), Decimal('-3'), Decimal('-6'), Decimal('-3'), Decimal('-6'), Decimal('6')]
* print (output)
* solve2by3 : parallel input.
* input =
* (Decimal('-181440'), Decimal('181440'), Decimal('-101088'))
* (Decimal('90720'), Decimal('-90720'), Decimal('406944'))
* checkDirectionNumbers : 3 rows form a tent.
* input of solve3by4 =
* [Decimal('-756'), Decimal('-1176'), Decimal('0'), Decimal('-1872')]
* [Decimal('-324'), Decimal('-744'), Decimal('240'), Decimal('-936')]
* [Decimal('-324'), Decimal('-384'), Decimal('-120'), Decimal('-264')]
* input of solveMbyN with 4 rows =
* [Decimal('-6'), Decimal('11'), Decimal('16'), Decimal('-4'), Decimal('20')]
* [Decimal('-66'), Decimal('-5'), Decimal('-20'), Decimal('-44'), Decimal('-92')]
* [Decimal('-42'), Decimal('23'), Decimal('-12'), Decimal('12'), Decimal('-16')]
* [Decimal('-18'), Decimal('-21'), Decimal('-16'), Decimal('-32'), Decimal('16')]
* input of solveMbyN with 5 rows =
* [Decimal('-4'), Decimal('-6'), Decimal('3'), Decimal('-4'), Decimal('-8'), Decimal('-8')]
* [Decimal('1'), Decimal('0'), Decimal('2'), Decimal('5'), Decimal('1'), Decimal('7')]
* [Decimal('9'), Decimal('-3'), Decimal('-8'), Decimal('4'), Decimal('7'), Decimal('-5')]
* [Decimal('1'), Decimal('-9'), Decimal('5'), Decimal('-2'), Decimal('5'), Decimal('-2')]
* [Decimal('1'), Decimal('-3'), Decimal('-6'), Decimal('-3'), Decimal('-6'), Decimal('6')]
* None

### Sphere

In cartesian coordinate geometry of three dimensions a sphere is represented by equation:
$x^{2}+y^{2}+z^{2}+Ax+By+Cz+D=0.$
On the surface of a certain sphere there are 4 known points:
What is equation of sphere?
Rearrange equation of sphere to prepare for creation of input matrix:
$(x)A+(y)B+(z)C+(1)D+(x^{2}+y^{2}+z^{2})=0.$
Create input matrix of size 4 by 5:
Equation of sphere is :
$x^{2}+y^{2}+z^{2}-8x+10y-24z-104=0$

### Quintic function

A quintic function $y=f(x)=Ax^{5}+Bx^{4}+Cx^{3}+Dx^{2}+Ex+F$ is defined by 6 points: $(-8,0),(-6,0),(-3,0),(1,0),(3,0),(5,10).$
What is $f(x)?$
$y=f(x)=Ax^{5}+Bx^{4}+Cx^{3}+Dx^{2}+Ex+F$
$A,B,C,D,E,F$ are 6 unknowns.
$x^{5}(A)+x^{4}(B)+x^{3}(C)+x^{2}(D)+x(E)+1(F)-y=0$
From these results the following ratios may be deduced:
${\frac {1}{A}}=915.2;\$ ${\frac {B}{A}}=13;\$ ${\frac {C}{A}}=25;\$ ${\frac {D}{A}}=-165;\$ ${\frac {E}{A}}=-306;\$ ${\frac {F}{A}}=432.$
$y=f(x)={\frac {x^{5}+13x^{4}+25x^{3}-165x^{2}-306x+432}{915.2}}$

### Resistive network

* Figure 1. Diagram of resistive network containing 8 resistors.
* A resistive network containing 8 resistors is connected as shown in Figure 1.
* What is resistance $R$ between points $P_{1},P_{3}?$

#### Solve for 8 Branch Currents

* input is matrix of size 8 by 9:
* [10, -20, 0, 0, 0, 0, -70, 0, 0], # e1 = e2 + e7, or r1(i1) - r2(i2) - r7(i7) = 0
* [ 0, -20, 30, 0, 0, 0, 0, -80, 0], # e3 = e2 + e8, or r3(i3) - r2(i2) - r8(i8) = 0
* [ 0, 0, 0, -40, 50, 0, -70, 0, 0], # e5 = e4 + e7, or r5(i5) - r4(i4) - r7(i7) = 0
* [ 0, 0, 0, 0, 50, -60, 0, -80, 0], # e5 = e6 + e8, or r5(i5) - r6(i6) - r8(i8) = 0
* [ 0, -1, 0, 0, 1, 0, 1, 1, 0], # i2 = i5 + i7 + i8, or 1(i5) + 1(i7) + 1(i8) - 1(i2) = 0
* [-1, 0, 0, 1, 0, 0, -1, 0, 0], # i4 = i1 + i7, or 1(i4) - 1(i1) - 1(i7) = 0
* [ 0, 0, -1, 0, 0, 1, 0, -1, 0], # i6 = i3 + i8, or 1(i6) - 1(i3) - 1(i8) = 0
* [ 1, 1, 1, 0, 0, 0, 0, 0, -1] # i1 + i2 + i3 = 1, or 1(i1) + 1(i2) + 1(i3) - 1 = 0

#### Make all Branch Currents positive

* Figure 3. Diagram of resistive network showing all branch currents positive.
* Make $i_{7}$ positive and check results.
* # Python code
* i7 *= -1
* values_of_e = e1,e2,e3,e4,e5,e6,e7,e8 = [
* eval(s1)
* for s in '12345678'
* for s1 in [ 'i' + s + '*r' + s ]
* s1 = 'values_of_e'
* print(s1,eval(s1))
* values_of_e [ 4.572738922236461, 6.130707493086937,
* 7.085721993660215, 17.400687934174144,
* 15.842719363323669, 14.88770486275039,
* 1.5579685708504756, 0.9550145005732785]
* # python code
* t1 = (
* 'e1+e7-e2', # e1 + e7 should equal e2
* 'e2+e8-e3', # e2 + e8 should equal e3
* 'e7+e5-e4', # e7 + e5 should equal e4
* 'e8+e6-e5', # e8 + e6 should equal e5
* 'e1+e4-(e2+e5)', # e1 + e4 should equal e2 + e5
* 'e1+e4-(e3+e6)', # e1 + e4 should equal e3 + e6
* 'e1+e7+e8-e3', # e1 + e7 + e8 should equal e3
* 'e7+e8+e6-e4', # e7 + e8 + e6 should equal e4
* 'i1-i7-i4', # i1 should equal i7 + i4
* 'i6-i3-i8', # i6 should equal i3 + i8
* 'i2+i7-(i8+i5)', # i2 + i7 should equal i8 + i5
* 'i1+i2+i3 - (i4+i5+i6)', # Total input current should
* # equal total output current.
* for s1 in t1 :
* print(s1,eval(s1))
* e1+e7-e2 -8.881784197001252e-16
* e2+e8-e3 0.0
* e7+e5-e4 0.0
* e8+e6-e5 0.0
* e1+e4-(e2+e5) 0.0
* e1+e4-(e3+e6) 0.0
* e1+e7+e8-e3 -8.881784197001252e-16
* e7+e8+e6-e4 0.0
* i1-i7-i4 -5.551115123125783e-17
* i6-i3-i8 6.938893903907228e-18
* i2+i7-(i8+i5) 0.0
* i1+i2+i3 - (i4+i5+i6) 0.0

#### Compute R

* # Python code
* E1 = e3+e6
* I1 = i1 + i2 + i3
* R1 = E1/I1
* s1 = 'R1' ; print(s1,eval(s1))
* E2 = e1 + e7 + e5
* I2 = i4 + i5 + i6
* R2 = E2/I2
* s1 = 'R2' ; print(s1,eval(s1))
* R1 21.973426856410605
* R2 21.973426856410605
* $R=R_{1}=R_{2}$

## Solving big matrices

A big matrix is one of size greater than 10 by 11.
With each recursive call of solveMbyN the size of each value in decimal digits can theoretically double. Python's integer math enjoys infinite precision. If your original matrix is of size 32 by 33, and each value in the matrix is an int of 1 decimal digit, function solve2by3 can be called with ints of size 2**30 (1,073,741,824) decimal digits.
Floats can be used instead of ints, but the limited precision of floats may not provide a desirable level of accuracy in the result.
Python's decimal objects are a good compromise and function reduceRow above is an attempt to keep the size of each member manageable.
Function reduceRow works well. However, as with all operations involving python's decimal objects, you need to pay careful attention to precision and accuracy of the results.
On my Mac the following python code generates a matrix of size 100 by 101 and calculates the result containing 100 values in about 1.5 seconds, including the time to generate 10,100 random numbers, each containing up to 12 decimal digits with the decimal point in a random position, and including the time to test output over 100 rows to verify that all calculated values of the solution satisfy each row.
In function solveMbyN above find line:
Change it to:
Then:

### Testing results

Data input to function solveMbyN is an array of 100 rows, each row containing 101 numbers.
Data received from function solveMbyN is an array of 100 numbers.
The first row is tested with the solutions by;
sum is the sum of all items in L2.
sum is appended to L1 and the process is repeated for all 100 rows.
Ideally sum should be zero.
In practice it's extremely unlikely that sum will be zero. My results typically gave values close to
The worst of the results above was 23 zeroes after the decimal point.
Better results can be achieved by increasing precision.

### Cubic Resistive Network

* Figure 1. Diagram of resistive network containing 12 resistors.
* Blue arrows show assumed direction of current.
* A resistive network containing 12 resistors is connected as shown in Figure 1.
* The network is called "cubic" because, in 3 dimensions, each resistor is located on one
* edge of a cube.
* What is resistance $R$ between points $P_{1},P_{2}?$
* # Python code:
* values_of_r = r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12 = 10,20,30,40,50,60,70,80,90,100,110,120

#### Solve for 12 Branch Currents
##### Create matrix 12 by 13

This matrix failed:

##### Try again
#### Compute R

* # python code
* values_of_e = e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12 = [ (i*r) for (i,r) in zip(values_of_i, values_of_r) ]
* values_of_e
* 55.0271714922048997772828507770 187.618551947798226077443050828 47.9999999999999999999999999970
* 194.645723440003125854725901608 306.450670105106865158441761408 135.048177235962958621498065875
* 327.968803969835501895049427569 113.530043371234321884890399714 639.244543429844097995545656989
* 387.821044816942132614386746358 359.275739460008596100496229430 440.391419528777400070331731324
* $e_{3}$ should be $48,\ i_{3}*r_{3}$ or $1.6*30.$
* E1 = e5 + e10 + e2
* I1 = i9 + i5 + i7
* R1 = E1/I1
* s1 = 'R1' ; print(s1,eval(s1))
* E2 = e7 + e8 - e6 + e10 - e1 + e3 + e4
* I2 = i2 + i4 + i12
* R2 = E2/I2
* s1 = 'R2' ; print(s1,eval(s1))
* R1 49.2208688540148837936367036806
* R2 49.2208688540148837936367036803
* Display results with precision of 28:
* dgt.prec = 28
* R1 += 0 ; R2 += 0
* dgt.prec = Precision
* s1 = 'R1' ; print(s1,eval(s1))
* s1 = 'R2' ; print(s1,eval(s1))
* R1 49.22086885401488379363670368
* R2 49.22086885401488379363670368
* $R=R_{1}=R_{2}.$

#### Review

In matrix all values $i_{1},i_{2},\dots ,i_{11},i_{12}$ and $e_{1},e_{2},\dots ,e_{11},e_{12}$ are included.
Testing was done with the following lines substituted for last line of matrix:
All tests produced a consistent value of $R.$

#### Checking
##### Examples of current nodes

* $i_{1}+i_{10}=i_{2}$
* $i_{6}+i_{8}=i_{12}$

##### Examples of voltage loops

* Top and Bottom.$e_{1}+e_{2}-e_{4}-e_{3}=0$$e_{5}+e_{6}-e_{8}-e_{7}=0$
* Two sides in background.$e_{5}+e_{10}-e_{1}-e_{9}=0$$e_{6}+e_{12}-e_{2}-e_{10}=0$
* Two sides in foreground.$e_{7}+e_{11}-e_{3}-e_{9}=0$$e_{8}+e_{12}-e_{4}-e_{11}=0$

##### Python code

Result of each of the above calculations should be $0.$
Because of small rounding errors, result may not be exactly $0.$
See values_of_i and values_of_e above.
This code verifies that result is close enough to $0$ to be acceptable.
For example:
${\text{result}}=e_{10}+e_{2}-e_{12}-e_{8}+e_{11}-e_{3}-e_{9}+e_{5}.$
${\text{v1}}=e_{10}+e_{2}+e_{11}+e_{5},$ sum of positive values.
${\text{status = (abs(result)}}<{\text{(v1}}*{\text{Tolerance)). status}}$ should be ${\text{True.}}$
| Calculation | Result | Result Acceptable |
| $i_{1}+i_{10}-i_{2}$ | $-1.2E-28$ | ${\text{True}}$ |
| $i_{1}+i_{3}-i_{9}$ | $-6E-29$ | ${\text{True}}$ |
| $i_{3}+i_{11}-i_{4}$ | $-3E-29$ | ${\text{True}}$ |
| $i_{10}+i_{6}-i_{5}$ | $0E-29$ | ${\text{True}}$ |
| $i_{11}+i_{8}-i_{7}$ | $0E-29$ | ${\text{True}}$ |
| $i_{6}+i_{8}-i_{12}$ | $-2E-29$ | ${\text{True}}$ |
| $i_{5}+i_{7}+i_{9}-i_{2}-i_{4}-i_{12}$ | $-3E-29$ | ${\text{True}}$ |
| $e_{1}+e_{2}-e_{4}-e_{3}$ | $0E-28$ | ${\text{True}}$ |
| $e_{5}+e_{6}-e_{8}-e_{7}$ | $0E-27$ | ${\text{True}}$ |
| $e_{9}+e_{1}-e_{10}-e_{5}$ | $0E-27$ | ${\text{True}}$ |
| $e_{10}+e_{2}-e_{12}-e_{6}$ | $-1.3E-26$ | ${\text{True}}$ |
| $e_{9}+e_{3}-e_{11}-e_{7}$ | $-1.3E-26$ | ${\text{True}}$ |
| $e_{11}+e_{4}-e_{12}-e_{8}$ | $0E-27$ | ${\text{True}}$ |
| $e_{8}-e_{6}+e_{10}+e_{2}-e_{4}-e_{3}-e_{9}+e_{7}$ | $0E-27$ | ${\text{True}}$ |
| $e_{10}+e_{2}-e_{12}-e_{8}+e_{11}-e_{3}-e_{9}+e_{5}$ | $0E-27$ | ${\text{True}}$ |

### Big Matrix 64 by 65

* Diagram of resistive network containing 64 resistors.
* Positive current flow is assumed to be from bottom to top or from left to right.
* A network containing 64 resistors is connected as shown in diagram.
* What is resistance R between points P1, P2?
* # python code
* values_of_R = (
* R10, R11, R12, R13, R14, R15, R16, R17, R18, R19,
* R20, R21, R22, R23, R24, R25, R26, R27, R28, R29,
* R30, R31, R32, R33, R34, R35, R36, R37, R38, R39,
* R40, R41, R42, R43, R44, R45, R46, R47, R48, R49,
* R50, R51, R52, R53, R54, R55, R56, R57, R58, R59,
* R60, R61, R62, R63, R64, R65, R66, R67, R68, R69,
* R70, R71, R72, R73,
* ) = [ v for v in range (100,731,10) ]
* While this resistive circuit may be very theoretical, it lends itself well to the creation of a big matrix, 64 by 65, meaning that there are 64
* resistors and 64 simultaneous equations to be solved.

#### Create matrix

An examination of the circuit produces the following conditions:
In iconditions and econditions there are 63 conditions that include all values of i and e. These 63 conditions are used to create matrix.
The 64th condition is added manually.
The matrix is:
Bottom line of matrix is equivalent to: $(1)i10+(-1)=0$ or $i10=1.$

#### First result

The following conditions are included for testing:
Produce results:
${\text{R}}$ is printed with precision of 60.

#### Matrix corrected

* Diagram of network containing 64 resistors
* Diagram has been corrected to show positive direction of current through R70, R73.
* Original assumptions were that currrent flow through 64 resistors would be from bottom to top or from left to right.
* Examination of results shows that flow through R70, R73 is from right to left. This is reflected in testing below.
* Corrected diagram conforms to assumption that all current flow is from bottom towards top or from left to right.
${\text{R}}$ is printed with precision of 56.
With precision of 56 all 64 results are equal.