8
$\begingroup$

Here is a simple representation of my problem.

I want to solve

Solve[(w^2*c^2 /. #) - 1 == 0, w]& /@ {{c -> 1}, {c -> 2}}
{{{w -> -1}, {w -> 1}}, {{w -> -(1/2)}, {w -> 1/2}}}

The thing is, I want to combine this with value of c like this

{{c->1, w->-1}, {c->1,w->1}, {c->2,w->-1/2}, {c->2,w->1/2}}

I used

Outer[Union, #, Solve[(w^2*c^2 /. #) - 1 == 0, w]] & /@ {{c -> 1}, {c -> 2}}

for this but it gives

Rule::argrx: Rule called with 4 arguments; 2 arguments are expected. >>.

What am I doing wrong? Is there a better way to do this ?

Note:The example which I gave is simple but my problem is generic. So instead of w^2*c^2 == 0 there can be any equation which can give any number of solutions.

$\endgroup$
6
$\begingroup$

I like this short one:

Solve[w^2 c^2 - 1 == 0 && (c == 1 || c == 2), {w, c}]
(*{{w -> -1, c -> 1}, {w -> 1, c -> 1}, {w -> -(1/2), c -> 2}, {w -> 1/2, c -> 2}}*)

It can be generalized as:

cvalues = {1, 2, 5, 6};
Solve[w^2 c^2 - 1 == 0 && Or @@ Thread[c == cvalues], {w, c}]
| improve this answer | |
$\endgroup$
3
$\begingroup$
ArrayReshape[Tuples /@ ({#, Solve[(w^2*c^2 /. #)-1 == 0, w]} & /@ {{c -> 1}, {c -> 2}}), {4, 2}]

or

Partition[Flatten[Tuples /@ ({#,Solve[(w^2*c^2 /. #)-1 == 0, w]} & /@ {{c -> 1}, {c -> 2}})], 2]

both give

(* {{c -> 1, w -> -1}, {c -> 1, w -> 1}, {c -> 2, w -> -(1/2)}, {c -> 2, w -> 1/2}} *)
| improve this answer | |
$\endgroup$
2
$\begingroup$
cc = {c -> 1, c -> 2};

sol = Solve[(w^2*c^2 /. #) - 1 == 0, w] & /@ cc;

Partition[Riffle[Riffle[cc, cc], Flatten @ sol], 2]

enter image description here

cc = {c -> 1, c -> 2, c -> 3};

sol = Solve[(w^2*c^2 /. #) - 1 == 0, w] & /@ cc;

Partition[Riffle[Riffle[cc, cc], Flatten @ sol], 2]

enter image description here

| improve this answer | |
$\endgroup$
  • 3
    $\begingroup$ riffle = {c -> 1, c -> 2}; ....; Partition[ Riffle[Riffle[riffle, riffle], Flatten@sol], 2] $\endgroup$ – Dr. belisarius Sep 22 '14 at 16:23
  • $\begingroup$ @belisarius lol $\endgroup$ – eldo Sep 22 '14 at 16:24
2
$\begingroup$
sol = Flatten[Solve[{w^2*c^2 - 1 == 0, c == #}, {c, w}] & /@ {1, 2}, 1]

{{c -> 1, w -> -1}, {c -> 1, w -> 1}, {c -> 2, w -> -(1/2)}, {c -> 2, w -> 1/2}}

sol == Flatten[
  Solve[{w^2*c^2 - 1 == 0, c == #}, {c, 
      w}] & /@ (c /. {{c -> 1}, {c -> 2}}), 1]

True

| improve this answer | |
$\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.