Don't like ads? PRO users don't see any ads ;-)

# Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 1.36 KB  |  hits: 12  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. How to combine all solutions within one list in Mathematica?
2. In[1]:= Solve[x == 1 &&  2 >= y >= 1, {x, y}, Integers]
3.     Out[1]= {{x -> 1, y -> 1}, {x -> 1, y -> 2}}
4.
5. {x->1, y->1,2}
6.
7. In[1]:= Solve[x == 1,{x}]
8.     Out[1]= {x -> 1}
9.     In[2]:= x
10.     Out[2]= x
11.     In[3]:= Definition[x]
12.     Out[3]= Null
13.     In[4]:= ?x
14.             Global`x
15.
16. vars = {x, y};
17.
18. sols = Solve[x == 1 && 2 >= y >= 1, vars, Integers];
19.
20. Thread[ vars -> Union /@ (vars /. sols) ]
21.
22. {x -> {1}, y -> {1, 2}}
23.
24. sols = Solve[x^2 + a x + 1 == 0, x]
25.
26. MapIndexed[(gg[#2[[1]]][a_] := #) &, x /. sols];
27.
28. Plot[gg[1][a], {a, 1, 4}]
29.
30. gg[2] /@ {1, 2, 3}
31.
32. {1/2 (-1 + I Sqrt[3]), -1, 1/2 (-3 + Sqrt[5])}
33.
34. In[3]:= sol = Solve[x == 1 && 2 >= y >= 1, {x, y}, Integers]
35. Out[3]= {{x -> 1, y -> 1}, {x -> 1, y -> 2}}
36.
37. In[4]:= x /. sol
38. Out[4]= {1, 1}
39.
40. In[5]:= Union[x /. sol]
41. Out[5]= {1}
42.
43. In[6]:= Union[y /. sol]
44. Out[6]= {1, 2}
45.
46. sol = Solve[x == 1 && 2 >= y >= 1, {x, y}, Integers]
47. x /. sol
48. Union[x /. sol]
49. Union[y /. sol]
50. Clear[sol]
51.
52. Solve[x == 1 && 2 >= y >= 1, {x, y}, Integers] /.  Rule[a_, b_] -> b
53.
54. {x -> #[[1]], y -> #[[2]]} &
55.
56. solutionlist = (Solve[x == 1 && 2 >= y >= 1, {x, y}, Integers] /.
57.        Rule[a_, b_] -> b ) // {x -> #[[1]], y -> #[[2]]} &
58.
59. {x -> {1, 1}, y -> {1, 2}}
60.
61. {xlist, ylist} = {x, y} /. solutionlist
62.
63. ?xlist
64.
65. {x -> Union@#[[1]], y -> Union@#[[2]]} &