# Solving a linear equation in Mathematica

This should be easy but I can't seem to find the right way to do it.

I have an equation of the form $a x + b x + c y + a z + d z = 0$, and I'd like to solve for relations between the parameters $a,b,c,d$, etc. such that the equation holds for all values of $x,y,z$, etc.

This is a very simplified example of the kind of equation I'm dealing with; there are actually 308 variables $x,y,\ldots$ and 42 parameters $a,b,\ldots$, making this nontrivial. As in the short sample equation, different variables could have the same parameter and could appear multiple times with different parameters.

So far my best attempt is:

````Solve[ForAll[{x, y, ...}, a*x + b*y + ... == 0], {a, b, ...}]
````

This yields the correct solution on a smaller equation (about 20 variables and 9 parameters) but is far too slow for this one. Is there a more specific technique I could use that's more optimized for this kind of problem specifically? Leaving out `ForAll` yields solutions in terms of the x-variables, which is kind of useless.

EDIT: nikie mentioned a much better way to do it (in the comments)! Thanks!

-

2
Isn't this equivalent to solving the equation system `a+b==0 && c==0 && a+d==0`, without `x,y,z` and `ForAll`? – nikie May 22 '12 at 20:26
Huh. Yes, I think so, now that you point it out. Thanks! I'll see if I can rework the larger equation into that form, shouldn't be too hard. – Abilinglortly May 22 '12 at 20:40

## 2 Answers

````Coefficient[a x + b x + c y + a z + d z, #] == 0 & /@ {x, y, z} // Reduce[#, {a, b, c, d}] &

b == -a && c == 0 && d == -a
````
-

You can use `SolveAlways` for the type of problems you describe. I haven't looked if it's fast enough for a very large system though.

````In[1]:= SolveAlways[a x + b x + c y + a z + d z == 0, {x, y, z}]

Out[1]= {{a -> -d, b -> d, c -> 0}}
````
-
lang-mma
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 5, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9006327986717224, "perplexity_flag": "middle"}