Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to solve this system for r and c but I get an error "Solve::ivar: r is not a valid variable.". What is wrong here?

Solve[2 c+2 r==2 s && (c+p+2 r)/c==(b+p+r)/(-b+r),{r ,c }]

Thanks.

share|improve this question
3  
Clear[r] first and then run your code. –  xzczd Apr 7 '13 at 11:23
add comment

closed as too localized by István Zachar, Artes, ssch, rm -rf Apr 7 '13 at 16:36

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers

I bet your error isn't

Solve::ivar: r is not a valid variable.

but

Solve::ivar: (* something, probably a number *) is not a valid variable.

And, if you delete some parts of your code, for example:

enter image description here

Look, do you feel something strange? If not, compare it with this one:

enter image description here

Now you must notice the difference, yeah, the colorings of r are different.

The colorings in Mathematica do make sense. Blue means that the global symbol has no value, including OwnValues, DownValues, SubValues, UpValues… and when the symbol gets either of the values, it turns black. One should always pay attention to the coloring. For your case, try the following code:

r = 1
Solve[2 c + 2 r == 2 s && (c + p + 2 r)/c == (b + p + r)/(-b + r), {r, c}]
(* The code above gives a warning *)    
Clear[r]
Solve[2 c + 2 r == 2 s && (c + p + 2 r)/c == (b + p + r)/(-b + r), {r, c}]
(* Now you get what you expect. *)

The issue of values really involves a lot, I'd like not to (and in fact, not be able to… ) cover the whole. You can get more information by checking the document and searching in this site.

share|improve this answer
add comment
 In[1]:= Solve[2 c + 2 r == 2 s && (c + p + 2 r)/c == (b + p + r)/(-b + r), {r, c}]

 Out[1]= {{r -> 1/2 (-p - Sqrt[2 b p + p^2 + 4 b s + 2 p s]), c -> 1/2 (p + 2 s + Sqrt[(2 b + p) (p + 2 s)])}, {r ->1/2 (-p + Sqrt[2 b p + p^2 + 4 b s + 2 p s]), c -> 1/2 (p + 2 s - Sqrt[(2 b + p) (p + 2 s)])}}

it works well in mathematica 8.0 !

share|improve this answer
    
by me too ! (mathematica 8.0.4) –  andre Apr 7 '13 at 12:14
add comment

I think the correct approach here should be:

Reduce[2 c + 2 r == 
2 s && (c + p + 2 r)/c == (b + p + r)/(-b + r), {r, c}]
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.