I'm trying to get Mathematica to solve a complicated equation for a particular variable using NSolve, with the conditions that the solutions must be real and $\geq 0$. Mathematica can solve the equation in general (including all numerical solutions, real and complex), however, when I impose the additional constraints, it doesn't seem to be able to compute the solutions in any reasonable amount of time. I have a feeling it might be something to do with the fact that for several of the input values there is more than one real, positive solution, but I might be mistaken.
Here is the code that I've written:
ClearAll["Global`*"];
dk = 0.6;
m = 1;
f = 7;
lattsize = 15;
p[P_, [\Alpha]_, β_] := {P*Sin[α]*Cos[β],
P*Sin[α]*Sin[β], P*Cos[α]}
q[Q_, a_] := {Q*Sin[a], 0, Q*Cos[a]}
k[X_] := {0, 0, X}
X = Interpolation[Table[{i, i}, {i, 0, lattsize, dk}]];
ω[x_] := Sqrt[x.x + m^2]
Subscript[A, 1][x_, y_, z_,s_] := (1+1/(8*ω[x]^2))*ω[x](1+1/(8*ω[y]^2))*ω[y]+(1+1/(8*ω[z]^2))*ω[z]+(1+1/(8*ω[s]^2))*ω[s](*//FullSimplify*)
sol1 = Table[(tempsol=NSolve[Subscript[A, 1][p[P,α,β],q[Q,a],k[X[i]],k[X[i]]-p[P,α,β]-q[Q, a]]==f&&Q∈Reals&&Q>=0,Q];
If[tempsol=={},{{P,i,α,β,a},0},{{P,i,α,0,0},Q/.tempsol[[1]]}]),{P,0,5},{i, 0,lattsize},{α,0,1},{β,0,2},{a,0,1}]
Eventually I want to be able to interpolate this table in order to create a function. Is there a better (i.e. quicker and more efficient) way to extract the real, positive solutions other than the way that I've done it?
I'm a bit of a novice when it comes to Mathematica, so any help and/or suggestions would be very much appreciated
x /. {x -> 4}, more detailed discussion Assign the results from a Solve to variable(s) – Artes Jan 23 '17 at 18:23