# Solve an equation in $\mathbb{R}^+$

How can I solve this equation (both numerically and literally) only in the positive reals $\mathbb{R}^+$?

Solve[x == (v0 - (A CD t v0^2 ρ)/(4m)) Cos[θ] t, t]


And for example, is there a way to have an output like this :

52.0756


and not like this :

{{t -> -52.3918}, {t -> 52.0756}}


?

• You can add a condition like sol=Solve[{...,t>0},t]; then you can do sol[[All,1,2]]. Commented Nov 6, 2012 at 12:26
• For the first leg of your question, there is a good tutorial in the documentation of Mathematica entitled "equations and inequalities over domains". Reduce is what you probably want to try out. As for the solutions being given as rules, the documentation of Solve has every possible way to extract those.
– gpap
Commented Nov 6, 2012 at 12:33

You could use ReplaceAll (i.e. /.) and Select

Select[x /. Solve[x^2 - 1 == 0, x], Positive]


gives

{1}

It is a list (List) not a single number. You might not know how many positive solutions exist:

Select[x /. NSolve[(x - 1) (x + 3) (x - 3) == 0, x], Positive]


{1., 3.}

Edit:

Using Part or its short-hand notation [[]] you can select parts from the list:

Part[{1}, 1]


1

{1}[[1]]


1

Part[{1.,3.},2]

3.
• Isn't possible remove from the output also the braces, right? Commented Nov 6, 2012 at 17:09
• @FormlessCloud Yes you can if you have one result, however how would you return 2 numbers without braces ? Commented Nov 6, 2012 at 17:25
• I have selected the positive reals appositely for have one result, but I don't know how to remove the braces from the output. I don't want the braces because I want use the result as a value for a command and if I keep the braces the result can't be taken as numerical value. Commented Nov 6, 2012 at 21:36
• @FormlessCloud I updated the answer to show how to get rid of the braces. Commented Nov 7, 2012 at 7:37

The first items of More Information in the documentation of Solve says :

• The system expr in Solve[expr,vars] can be any logical combination of:

lhs == rhs               equations
lhs != rhs               inequations
lhs > rhs or lhs >= rhs  inequalities
expr ∈ dom               domain specifications
ForAll[x,cond,expr]      universal quantifiers
Exists[x,cond,expr]      existential quantifiers

• Solve[{ expr1, expr2,...},vars] is equivalent to Solve[ expr1 && expr2 &&...,vars].

Every expri can be an equation, inequality as well as an expression tests like e.g. Positive or Negative etc., thus we can do simply e.g. Solve[-36 + 49 x^2 - 14 x^4 + x^6 == 0 && x > 0, x], but to get only the list of solutions (without Rules ) there are at least two ways:

• using ReplaceAll (shorthand /.) (mentioned by Markus Roellig) with the condition x > 0 :

x/.Solve[-36 + 49 x^2 - 14 x^4 + x^6 == 0 && x > 0, x]

{1, 2, 3}

• using Part (shorthand [[]]) with e.g. x > 0 or with an expression test like Positive, NonNegative etc.:

Solve[-36 + 49 x^2 - 14 x^4 + x^6 == 0 && Positive[x], x][[All, 1, 2]]

 {1, 2, 3}


The above ways can be mixed, e.g. : x /. Solve[-36 + 49 x^2 - 14 x^4 + x^6 == 0 && x > 0, x][[3]]. We needn't point out the domain Reals since the condition x > 0 implies that x is a positive and real number. The same concerns Reduce, i.e. use it like e.g.

Reduce[-36 + 49 x^2 - 14 x^4 + x^6 == 0 && x > 0, x][[All, 2]]

• Not valid in Mathematica 6, I think? Commented Sep 12, 2014 at 0:04
• @SanjayManohar What do you mean? Solve has been updated since the version 6 nevertheless all this syntax was valid, or perhaps you missed something? Commented Sep 12, 2014 at 0:12
• on Mathematica 6.0: Solve[-36 + 49 x^2 - 14 x^4 + x^6 == 0 && x > 0, x] ==> "Solve::eqf : x>0 is not a well-formed equation" Commented Sep 13, 2014 at 8:28
• @SanjayManohar In version 6 one could do it with Reduce e.g. Reduce[-36 + 49 x^2 - 14 x^4 + x^6 == 0 && x > 0, x], Solve has worked this way since version 8, before equations had to be given in the form lhs == rhs only, although e.g. ForAll, Exists had been introduced in version 5. Commented Sep 13, 2014 at 8:57