MATLAB: System of equation for a vectors

non linear system of equationssystem of equationsvectors

Hi I would like to solve this system of equation (3 equation 3 unknown). Here, x, y and z are unknown and L1, L2, L3 are given numbers.
eqn(1)=[(L1-z)^2+(L1-y)^2+(L1-x)^2-L1^2==0];
eqn(2)= [(L2-z)^2+(L2-y)^2+(L2-x)^2-L2^2==0];
eqn(2)= [(L3-z)^2+(L3-y)^2+(L3-x)^2-L3^2==0];
It is ferly easy if it is for only one set of variables, but the problem is that the L1, L2 and L3 are separate vectors with more than 10000 rows, hence the system of equation should be solved more than 10000 times to find a vectors of x, y, and z.
Could you please give me a hint how to solve it and find such vectors of x, y and z?

Best Answer

Is it correct that L1, L2, L3 are 2D arrays in which the rows are independent, but any given row contributes a vector of L1, L2, L3 values that have to go into the equations to be solved for the x, y, z that simultaneously satisfy all of the equations?
If so then you have a size conflict on constructing the equation using a single subscript: if, for example, L1 is (say) 5 x 3, then any given row, K, would have
(L1(K,1)-z)^2+(L1(K,1)-y)^2+(L1(K,1)-x)^2-L1(K,1)==0,
(L1(K,2)-z)^2+(L1(K,2)-y)^2+(L1(K,2)-x)^2-L1(K,2)==0,
(L1(K,3)-z)^2+(L1(K,3)-y)^2+(L1(K,3)-x)^2-L1(K,3)==0
as simultaneous equations, and that would not fit within eqn(1) .
If we correct that to eqn(1,:) and so on, and fix the third entry to eqn(3) instead of eqn(2), then except for the case where L1, L2, L3 are column vectors rather than 2D, then there are no solutions.
The column vector case is easy to deal with:
syms x y z L1_ L2_ L3_
eqn(1) = [(L1_-z)^2+(L1_-y)^2+(L1_-x)^2-L1_^2==0];
eqn(2) = [(L2_-z)^2+(L2_-y)^2+(L2_-x)^2-L2_^2==0];
eqn(3) = [(L3_-z)^2+(L3_-y)^2+(L3_-x)^2-L3_^2==0];
sol = solve(eqn, [x, y, z]);
size(sol.x) now gives 0, so you can solve for all entries in L1, L2, L3 simultaneously by just saying that the solutions are all empty. Your system has no solution.
If you solve the first two equations simultaneously for x and y, and you substitute those into the third equation and simplify the third equation, then what you get is
(2*(L2_-L3_))*(L1_-L3_) == 0
which is independent of z, and is solved if L3 is the same as either L1 or L2 and otherwise has no solution.