Re: Separating square roots

*To*: mathgroup at smc.vnet.net*Subject*: [mg127251] Re: Separating square roots*From*: Peter Pein <petsie at dordos.net>*Date*: Wed, 11 Jul 2012 02:20:43 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*Delivered-to*: mathgroup-newout@smc.vnet.net*Delivered-to*: mathgroup-newsend@smc.vnet.net*References*: <jtgbrm$49j$1@smc.vnet.net>

Am 10.07.2012 06:42, schrieb rhartley.anu at gmail.com: > I have an expression which is a sum of terms, some monomials > and others involving square roots, such as > A = 3 + 5 x^2 + 7 x + Sqrt[5+x] + 7 x Sqrt[5+x] (but much more complicated). > I want to solve this, which involves separating terms with the square root > from those that do not have a square root, then squaring each. > > I can not work out how to separate out those terms that have the square > root. I do not want to hard code, such as nosqrt = A[[1]] + A[[2]] , etc. > Can anyone help? > > r > > This will work if all square roots are of the form Sqrt[a +/- b] (I think). And you'll get additional solutions which do not solve A==0. Try: A = 3 + 5*x^2 + 7*x + Sqrt[5 + x] + 7*x*Sqrt[5 + x]; sep = Apply[Plus, With[{sel = FreeQ[#1, _^(1/2)] & }, Split[SortBy[List @@ #1, sel], sel[#1] == sel[#2] & ] ], {1}] & ; tmp = Function[x, Evaluate[Expand[Subtract @@ (sep[A]^2)]]] soln = Select[ ({x -> #1} & ) /@ Table[Root[tmp, k], {k, Exponent[tmp[x], x]}], 10^(-8) > Abs[N[A /. #1]] & ] soln === Solve[A == 0, x, Quartics -> False] nx0 = Chop[N[x /. soln]] ==> Function[x,-4+29 x+180 x^2-21 x^3-25 x^4] {{x->Root[4-29 #1-180 #1^2+21 #1^3+25 #1^4&,1]}, {x->Root[4-29 #1-180 #1^2+21 #1^3+25 #1^4&,2]}} True {-3.06206,-0.246324} Peter P.S.: to visualize additional roots, enter with the results from above: Plot[Evaluate[(Sign[#1]*Log[1 + Abs[#1]] & )[{A, tmp[x]}]], Evaluate[Prepend[(x /. NSolve[tmp[x] == 0, x, Reals])[[{1, -1}]] + {-0.1, 0.1}, x]], Frame -> True, Axes -> {True, False}, AxesStyle -> Lighter[Gray], Epilog -> {Red, PointSize[1/100], Point[Thread[{Cases[nx0, _Real], 0}]]}, PlotRange -> All]