wolfram mathematica - Solving system of quadratic equations -


can see way solve system below? tried reduce evaluation takes while i'm not sure work

terms = {{g^2, g h, h^2, -o^2, -o p, -p^2}, {g^2, g k,      k^2, -o^2, -o q, -q^2}, {g^2, g m, m^2, -o^2, -o r, -r^2}, {g^2,      g n, n^2, -o^2, -o s, -s^2}, {h^2, h k,      k^2, -p^2, -p q, -q^2}, {h^2, h m, m^2, -p^2, -p r, -r^2}, {h^2,      h n, n^2, -p^2, -p s, -s^2}, {k^2, k m,      m^2, -q^2, -q r, -r^2}, {k^2, k n, n^2, -q^2, -q s, -s^2}, {m^2,      m n, n^2, -r^2, -r s, -s^2}}; vars = variables@flatten@terms; coefs = array[c, dimensions[terms]]; eqs = mapthread[#1.#2 == 0 &, {terms, coefs}]; reduce[eqs, vars, reals] 

you can approach problem optimization perspective, building sum of squares of r.h.s. of equations.

define matrix:

mat[{g_, h_, k_, m_, n_, o_, p_, q_, r_, s_}] := {{g^2, g h,      h^2, -o^2, -o p, -p^2}, {g^2, g k, k^2, -o^2, -o q, -q^2}, {g^2,      g m, m^2, -o^2, -o r, -r^2}, {g^2, g n,      n^2, -o^2, -o s, -s^2}, {h^2, h k, k^2, -p^2, -p q, -q^2}, {h^2,      h m, m^2, -p^2, -p r, -r^2}, {h^2, h n,      n^2, -p^2, -p s, -s^2}, {k^2, k m, m^2, -q^2, -q r, -r^2}, {k^2,      k n, n^2, -q^2, -q s, -s^2}, {m^2, m n, n^2, -r^2, -r s, -s^2}}; 

now define code solve algebraic equation constrained optimization:

clear[solvealgebraic]; solvealgebraic[   coefs_ /; dimensions[coefs] == {10, 6} && matrixq[coefs, numberq],    opts : optionspattern[nminimize]] :=   module[{g, h, k, m, n, o, p, q, r, s, eqs, vars, val, sol},   eqs = mapthread[#1.#2 &, {mat[       vars = {g, h, k, m, n, o, p, q, r, s}], coefs}];   {val, sol} =     nminimize[{total[eqs^2],       vars.vars > 1 && apply[and, thread[vars >= 0]]}, vars, opts];   {val, vars /. sol}   ] 

now define function constructs set of c[,] given solution:

coefficientwithsolution[sol_ /; length[sol] == 10] :=   block[{cc,     v}, ((array[        cc, {10, 6}]) /. (first[         quiet@solve[(mapthread[               dot, {mat[array[v, 10]], array[cc, {10, 6}]}] == 0 //              thread), array[cc, {10, 6}] // flatten]] /.         thread[array[v, 10] -> (sol)]) /. _cc :> 1)] 

generate matrix:

in[188]:= coefs =   coefficientwithsolution[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}]  out[188]= {{1, 1, 1, 1, 1, -(71/49)}, {1, 1, 1, 1, 1, -(71/64)}, {1,    1, 1, 1, 1, -(23/27)}, {1, 1, 1, 1, 1, -(13/20)}, {1, 1, 1, 1,    1, -(43/32)}, {1, 1, 1, 1, 1, -(28/27)}, {1, 1, 1, 1,    1, -(4/5)}, {1, 1, 1, 1, 1, -(11/9)}, {1, 1, 1, 1, 1, -(19/20)}, {1,    1, 1, 1, 1, -(11/10)}} 

solve equations higher working precision, , coerce machine numbers:

in[196]:= solvealgebraic[coefs, workingprecision -> 30] // n  out[196]= {1.41177*10^-28, {0.052633, 0.105266, 0.157899, 0.210532,    0.263165, 0.315798, 0.368431, 0.421064, 0.473697, 0.52633}} 

verify expected solution found:

in[197]:= rest[last[%]]/first[last[%]]  out[197]= {2., 3., 4., 5., 6., 7., 8., 9., 10.} 

hope helps.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -