Using solution of an equation [duplicate]

This question already has an answer here:

I want to solve something like f(x)=0 and then have the real solution be set as the value of another variable. I can't figure out how to do it. I tried something like this as an example, but it didn't work.

a = Solve[x + 1 == 0, x, Reals]


added: Why won't my InputField dynamically update?

InputField[ Dynamic[G = x /. Solve[ 2 == x*Cos[\[Theta]] -(P*x^2)/(6*C*D) (3 F + x) Sin[\[Theta]], x, Reals]]]


second add: here's the rest of my code.

    Manipulate[
DynamicModule[{P = 0, C = 1, D = 1, F = 0, θ = 0},
Deploy[Style[
Panel[Grid[Transpose[{{"P", "C", "D", "F", "θ", "G"},
{InputField[Dynamic[P]], InputField[Dynamic[C]],
InputField[Dynamic[D]], InputField[Dynamic[F]],
InputField[Dynamic[θ]],
InputField[
Dynamic[
G = x /.
Solve[2 ==
x*Cos[θ] - (P*x^2)/(
6*C*D) (3 F + x) Sin[θ], x, Reals][[1]]]]}}],
Alignment -> Right], ImageMargins -> 10, DefaultOptions ->
{InputField -> {ContinuousAction -> True,
FieldSize -> {{5, 30}, {1, Infinity}}}}]]] Dynamic[Show[
{Graphics[{Opacity[0.5], Red,
Rectangle[{1, 0}, {2, 1}]},
PlotRange -> {{-1, 2}, {-3, 3}}, Axes -> True,
AxesOrigin -> {0, 0}],
ParametricPlot[{x*Cos[θ] - (P*x^2)/(
6*C*D) (3 F + x) Sin[θ],
x*Sin[θ] + (P*x^2)/(6*C*D) (3 F + x) Cos[θ] +
G*Sin[θ] + (P*G^2)/(6*C*D) (3 F + G) Cos[θ] -
2}, {x, 0, B}, Axes -> True]}]]]]


marked as duplicate by Jens, MarcoB, user9660, Yves Klett, ArtesJul 8 '16 at 8:13

You want to run

a = x /. Solve[x + 1 == 0, x, Reals][[1]]


The [[1]] selects the first solution, and the x /. applies the solution to the expression x.

• Just what I needed. Thanks! – rxc370 Jul 8 '16 at 1:57
• Quick question: I want to do dynamic solve inside of a InputField. What am I doing wrong now? *added to OP – rxc370 Jul 8 '16 at 2:17
• I don't know which variables are symbolic and which are numerical, but the Solve is very slow. Also, don't use capital variables. I run: g = x /. Solve[ 2 == xCos[[Theta]] - (px^2)/(6*c*d) (3 f + x) Sin[[Theta]], x, Reals][[1]] InputField[Dynamic[g]] and this displays a result. If I set values for p, c, d, f, and theta, it gives numerics correctly. – Alex Meiburg Jul 8 '16 at 2:24
• I posted the rest of my code. I will definitely change the uppercase variables to lowercase. You can try running the code and you'll see that the last InputField (which is for G) doesn't update. Btw, thanks for your help. You're a lifesaver :) – rxc370 Jul 8 '16 at 2:30