Trilateralization is basically a distancedistance intersection using two or more points and corresponding measurements from them to an unknown point.
Working with just two points can yield 0, 1 or 2 solutions.
Case 1: No Solutions

Given
 Two points with fixed X,Y ( Points A and B)
 Two measurements from fixed Points (A &B ) to the Unknown Point (P)

Results
 If the sum of the measurements from A to P and B to P is less than the distance A to B then there cannot be an intersection
Case 2: One Solution

Given
 Two points with fixed X,Y ( Points A and B)
 Two measurements from fixed Points (A &B ) to the Unknown Point (P)

Results
 The sum of the measurements from point A to P and B to P, equals the distance (A to B), thus point P must lie on the line AB
Case 3: Two Solutions

Given
 Two points with fixed X,Y ( Points A and B)
 Two measurements from fixed Points (A &B ) to the Unknown Point (P)

Results

If the sum of the measurements from A to P and B to P, are greater than the distance (A to B) then there exists two possible solutions. CircleCircle Intersection

The least squares part of this occurs when you have 3 or more fixed points, and a measurement from each to the unknown point ( P ). Like shown here:
Assume Points A, B, C and D are fixed. Point P is unknown.
Chain Rule _ Dist Equation – Derivative
A different approach this time. Instead of showing each iteration in expanded form, I am going to introduce the matrices in the form of MathCAD functions. We can them solve them in a MathCAD Program Block.
Above is the MathCAD Program Block. Where we define the program, like a function, where it takes the matrix ‘pt’, the column vector ‘P’, and the double ‘tol’ and an integer ‘n’. However, MathCAD does not have strict variable declaration but the way I access the variables will error out if they aren’t passed in the method described.
SolveIt yields us the solution for point P and the variance from the measurements.
*EDIT – I found and corrected error in the J Matrix above. If you are revisiting the site be sure to refresh the page. Sorry.*
Dave