1
$\begingroup$

I am trying to solve a system of overdetermined linear equations for 2 unknowns with 3 variables.

For a given equation of a line, we can write it as: ax + by = c,

which expressed in vector form is Transpose(a)x=c, where a = (a b) and x = (x y).

So far, I've managed to get my code to a point where I can calculate what x1, x2, and x3 are, but I don't know how to loop it in a way that Mathematica will calculate it until the 3 variables converge.

This is what I have done so far: For a list of 3 equations and 2 unknowns:

Subscript[L, 1]: 4x+y=6, Subscript[L, 2]: 5x-y=1, Subscript[L, 3 ]: 2x-3y=4

x0 = {3, 1};
a1 = {4, 1};
x1 = x0 + ((6 - a1.x0)/a1.a1)*a1
a2 = {5, -1};
x2 = x1 + ((1 - a2.x1)/a2.a2)*a2
a3 = {2, -3};
x3 = x2 + ((4 - a3.x2)/a3.a3)*a3

Doing this gives you the points. And to loop it, I thought of defining the equations and then giving it initial parameters to calculate it, but I don't think it works.

eqns = {x1[x0] == x0 + ((6 - a1.x0)/a1.a1)*a1, 
  x2[x1] == x1 + ((1 - a2.x1)/a2.a2)*a2, 
  x3[x2] == x2 + ((4 - a3.x2)/a3.a3)*a3}; inits = {??}

Does anyone have advice? Or whether this kind of question has been asked before?

$\endgroup$
4
$\begingroup$

For one iteration I'd use FoldList:

iter[x_, {a_, c_}] = x + (c - a.x)/a.a a;
A = {{{4, 1}, 6}, {{5, -1}, 1}, {{2, -3}, 4}};
FoldList[iter, {3, 1}, A]

{{3, 1}, {23/17, 10/17}, {79/221, 174/221}, {271/221, -114/221}}

So you can define the process of going from $x_0$ to $x_3$ with

oneloop[x_] := Fold[iter, x, A]

and then nest this oneloop until convergence:

x0inf = FixedPoint[oneloop, {3, 1} // N]

{0.521614, -0.985591}

From this, recover the three points $\{x_1,x_2,x_3\}$ with

Rest@FoldList[iter, x0inf, A]

{{1.67435, -0.697406}, {0.122589, -0.387054}, {0.521614, -0.985591}}

Alternatively, look for an analytic solution for x0inf with

x0inf = {x,y} /. First[Solve[Thread[oneloop[{x,y}]=={x,y}], {x,y}]]

{181/347, -342/347}

from which you get the three points as before,

Rest@FoldList[iter, x0inf, A]

{{581/347, -242/347}, {553/4511, -1746/4511}, {181/347, -342/347}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.