0
$\begingroup$

I have the following system of equations:

edges = ({
{1, -1, 0, 0, 0, 0},
{0, 1, -1, 0, 0, 0},
{1, 0, -1, 0, 0, 0},
{1, 0, 0, -1, 0, 0},
{0, 1, 0, 0, -1, 0},
{0, 0, 1, 0, 0, -1},
{0, 1, 0, -1, 0, 0},
{0, 0, 1, 0, -1, 0},
{1, 0, 0, 0, 0, -1},
{0, 0, 0, 1, -1, 0},
{0, 0, 0, 0, 1, -1},
{0, 0, 0, 1, 0, -1}
});lf ={174.268, 174.268, 174.268, 278.04, 278.04, 278.04, 209.21, 209.21, \
209.21, 174.268, 174.268, 174.268};xf = {x1, -50, -50, x4, x5, x6}; yf = {y1, 
y2, -86.6025, y4, y5, y6}; zf = {0, 0, 0, z4, z5, 
z6}; lfsol = NSolve[
Table[lf[[i]] == 
Diagonal[\[Sqrt](DiagonalMatrix[(edges.xf)^2] + 
     DiagonalMatrix[(edges.yf)^2] + 
     DiagonalMatrix[(edges.zf)^2])][[i]], {i, 1, 12}], {x1, x4, 
x5, x6, y1, y2, y4, y5, y6, z4, z5, z6}, Reals]

The value of the unknown y2 can be directly found by solving the second equation of the system (i=2). However, by using such formulation the computational time seems to be very high. If I evaluate y2 as above, that is:

y2f = Solve[lf[[2]] == Sqrt[(86.6025 + y2)^2], {y2}][[2]]

and I replace y2/.y2f in NSOlve, the feasible solution lfsol[[7]] (the feasibility of the solution is consistent with a problem that does not affect this question) does not match the value of y2.

Where is the error?

$\endgroup$

2 Answers 2

3
$\begingroup$

Try NMinimize to solve the problem

eqn = Table[lf[[i]] ==Diagonal[\[Sqrt](DiagonalMatrix[(edges.xf)^2] + DiagonalMatrix[(edges.yf)^2] + DiagonalMatrix[(edges.zf)^2])][[i]], {i, 1, 12}];

NMinimize[{1, eqn}, {x1, x4, x5, x6, y1, y2, y4, y5, y6, z4, z5, z6}]
(*{1., {x1 -> 100.921, x4 -> -97.7232, x5 -> 29.7027, x6 -> 68.9411,y1 -> 0.531502, y2 -> 87.6655, y4 -> 23.1858, y5 -> -95.6922,y6 -> 74.1009, z4 -> 193.219, z5 -> 193.219, z6 -> 193.219}}*)
$\endgroup$
4
$\begingroup$

I do not know why NSolve is slow but if you artificially raise precision on the input then it is reasonably fast.

vars = {x1, x4, x5, x6, y1, y2, y4, y5, y6, z4, z5, z6};
origexprs = 
  Sqrt[Diagonal[(DiagonalMatrix[(edges.xf)^2] + 
       DiagonalMatrix[(edges.yf)^2] + 
       DiagonalMatrix[(edges.zf)^2])]] - lf;
Timing[realsolns = 
   NSolve[SetPrecision[origexprs, 200], vars, Reals];]
Length[realsolns]

(* Out[4763]= {1.108, Null}

Out[4764]= 16 *)
$\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.