2
$\begingroup$

I am trying to solve a system equations for rational, constant coefficients:

ord = 3;
vars = {a, b, c, d, e};
Do[tt[nn] = Total[vars^nn], {nn, 1, ord}];
mm = (Expand[tt[1]^ord] /. mm_^nn_ -> 0)/ord! // Expand; (*Sum of products of all unique sets of 3*)
expr = cc[1]*tt[1]^3 + cc[2]*tt[2]*tt[1] + cc[3]*tt[3] - mm;
aa = Solve[{expr == 0}, {cc[1], cc[2], cc[3]}]

(*{{cc[3] -> -((-a b c - a b d - a c d - b c d - a b e - a c e - b c e - a d e - b d e - c d e)/(a^3 + b^3 + c^3 + d^3 + e^3)) - ((a + b + c + d + e)^3 cc[1])/(a^3 + b^3 + c^3 + d^3 + e^3) - ((a + b + c + d + e) (a^2 + b^2 + c^2 + d^2 + e^2) cc[2])/(a^3 + b^3 + c^3 + d^3 + e^3)}} *)

This is the correct result for an under-determined system like this one, with 1 eqn and 3 unknowns. However, if we require that the cc[]'s be rational constants, i.e. independent of {a, b, c, d, e}, then the only solution (which I calculated by hand) is:

bb = {cc[1] -> 1/6, cc[2] -> -1/2, cc[3] -> 1/3};
expr /. bb // Expand

(* 0 *)

How can I get such solns from MMa? How does one impose the condition that the soln coefficients must be rational constants?

Ultimately, I need to do this with arbitrarily large vars lists and larger values of ord where ord < Length[vars].

$\endgroup$
7
$\begingroup$

Take a look at SolveAlways (documentation page). In this case:

SolveAlways[expr == 0, vars]
(* Out: {{cc[1] -> 1/6, cc[2] -> -(1/2), cc[3] -> 1/3}} *)

It may be, however, that in a more complicated expression you might obtain multiple sets of values for the parameters, and you may have to refine the results to pick those in which all cc[] parameters are rational.

SolveAlways is actually just a "shortcut" for the following Solve expression (see the "Details and Options" section of its documentation):

SolveAlways[expr == 0, vars]
(* is equivalent to *)
Solve[!Eliminate[!expr == 0, vars], Array[cc, 3]]

so you could use the version written with Solve and explicitly request that solutions be rational by specifying a domain:

Solve[!Eliminate[!expr == 0, vars], Array[cc, 3], Rationals]
$\endgroup$
  • $\begingroup$ Why can't all Answers be this simple? Thanks! $\endgroup$ – Jerry Guern Jun 15 '15 at 3:26
  • $\begingroup$ @JerryGuern glad it helped, and thank you for the accept! $\endgroup$ – MarcoB Jun 15 '15 at 3:31
  • $\begingroup$ I have never seen exclamation points used the way you've used them in the code you added. Is "!expr==0" the same a "expr!=0"? What do the two !'s in that code do? Very intriguing. $\endgroup$ – Jerry Guern Jun 15 '15 at 6:46

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.