3
$\begingroup$

So, I'm trying to solve a class of equations, and get all the solutions in a list. The general form looks like this:

c == a*Sqrt[1-n] PlusMinus[b * Sqrt[n]]

Please forgive if that's wrong, I'm really new to Mathematica.

The twist to this? c, a, and b all need to iterate separately through the integer values from -3 to 3. I need to get all solutions of n, positive and negative, for all combinations of these integer values. How would I write code to do that iteration for me, and get all the possible values of n in a list as output?

EDIT: I tried this in response to that first answer after reading Solve pretty carefully. I know this is horrendously wrong- what, though?

ClearAll[a, b, c, domainstate, domainstatea, domainstateb, \
    domainstatec]
domainstatea = a \[Element] Integers && a >= -3 && a <= 3  
domainstateb = b \[Element] Integers && b >= -3 && b <= 3 
domainstatec = c \[Element] Integers && c >= -3 && c <= 3 
domainstate = domainstatea && domainstateb && domainstatec
Solve[a*Sqrt[1 - n] \[PlusMinus] b * Sqrt[n] == c && domainstate, n]
$\endgroup$
5
  • 2
    $\begingroup$ The code is, indeed not right, since the PlusMinus is only for representation, not for calculations. Your problem looks trivial, but without a correct equation there is no sense doing anything. Anyway, check Menu/Help/WolframDocumentation/Solve. $\endgroup$ Commented Sep 28, 2015 at 14:06
  • $\begingroup$ Hey, I updated it, Would you mind taking another look? Thanks! $\endgroup$
    – laudiacay
    Commented Sep 28, 2015 at 14:16
  • $\begingroup$ Now I'm getting this error that it isn't solvable with the methods available to solve? I know for a fact that there are solutions to this in this space. $\endgroup$
    – laudiacay
    Commented Sep 28, 2015 at 14:19
  • 1
    $\begingroup$ I guess that you mean c == a*Sqrt[1-n]+b * Sqrt[n] and c == a*Sqrt[1-n]-b * Sqrt[n] . Is it right? Or you mean a multiplication like `a*Sqrt[1-n] *b * Sqrt[n] `` ?? $\endgroup$ Commented Sep 28, 2015 at 14:27
  • $\begingroup$ It was the first one. $\endgroup$
    – laudiacay
    Commented Sep 28, 2015 at 17:40

3 Answers 3

4
$\begingroup$

Here is the solution of a possible interpretation of your question.

Clear[a, b, c, n, sol]

First solve the equation with unspecified parameters a, b, and c: (The plus minus in the OP sign is incorporated in the parameter b):

sol = Solve[c == a Sqrt[1 - n] + b Sqrt[n], n]

(*
Out[919]= {{n -> (a^4 + a^2 b^2 - a^2 c^2 + b^2 c^2 - 
    2 Sqrt[a^4 b^2 c^2 + a^2 b^4 c^2 - a^2 b^2 c^4])/(
   a^4 + 2 a^2 b^2 + b^4)}, {n -> (
   a^4 + a^2 b^2 - a^2 c^2 + b^2 c^2 + 
    2 Sqrt[a^4 b^2 c^2 + a^2 b^4 c^2 - a^2 b^2 c^4])/(a^4 + 2 a^2 b^2 + b^4)}}
*)

There are two solutions n1 and n2.

The we calculate the solutions when each of the parameters take the integer values from -3 to +3.

The format is {{a,b,c},{n1,n2}}

Flatten[Table[{{a, b, c}, n /. sol}, {a, -3, 3}, {b, -3, 3}, {c, -3, 3}] // 
  Quiet, 2]
(* we shall show only a few lines *)

(*
{
{{-3, -3, -3}, {0, 1}}, 
{{-3, -3, -2}, {1/324 (162 - 36 Sqrt[14]), 1/324 (162 + 36 Sqrt[14])}}, 
{{-3, -3, -1}, {1/324 (162 - 18 Sqrt[17]), 1/324 (162 + 18 Sqrt[17])}}, 
{{-3, -3,  0}, {1/2, 1/2}}, {{-3, -3, 1}, 
{1/324 (162 - 18 Sqrt[17]), 1/324 (162 + 18 Sqrt[17])}}, 
{{-3, -3, 2}, {1/324 (162 - 36 Sqrt[14]), 1/324 (162 + 36 Sqrt[14])}}, 
{{-3, -3, 3}, {0, 1}}, 
{{-3, -2, -3}, {0, 144/169}}, 
{{-3, -2, -2}, {25/169, 1}}, 
{{-3, -2, -1}, {1/169 (112 - 24 Sqrt[3]), 1/169 (112 + 24 Sqrt[3])}}, 
{{-3, -2, 0}, {9/13, 9/13}}, 
{{-3, -2, 1}, {1/169 (112 - 24 Sqrt[3]), 1/169 (112 + 24 Sqrt[3])}},
...
} 
*)
$\endgroup$
3
$\begingroup$
Off[Solve::ifun]

max = 3;

Join[{{"a", "b", "c", "sign", "n"}}, 
  Table[{a, b, c, sign, Solve[c == a*Sqrt[1 - n] + sign*b*Sqrt[n], n]},
    {a, -max, max}, {b, -max, max}, {c, -max, max}, {sign, {-1, 1}}] //
    Flatten[#, 3] &] // Grid[#, Frame -> All] &

enter image description here

< deleted section >

enter image description here

To get Table sorted by largest absolute value of n

Join[{{"a", "b", "c", "sign", "n", "N[|n|]"}},
  SortBy[
    Select[ (* delete cases without solution *)
     Table[
       {a, b, c, sign,
        sol = n /. Solve[
           c == a*Sqrt[1 - n] + sign*b*Sqrt[n], n],
        Abs[sol] // Union // N},
       {a, -max, max},
       {b, -max, max},
       {c, -max, max},
       {sign, {-1, 1}}] // Flatten[#, 3] &,
     FreeQ[#, n] &],
    Max[Abs[#[[-1]]]] &] // Reverse] //
 Grid[#, Frame -> All] &
$\endgroup$
2
  • 2
    $\begingroup$ @ Bob Hanlon: nice table, Bob. $\endgroup$ Commented Sep 28, 2015 at 14:30
  • 1
    $\begingroup$ Gorgeous! This is exactly what I need. Is there a way I could get exact forms and absolute values of all the solutions and sort them in numerical order? $\endgroup$
    – laudiacay
    Commented Sep 28, 2015 at 14:32
1
$\begingroup$
Flatten@(Solve[#, n] & /@ 
    Flatten@Table[{a Sqrt[1 - n] + b*Sqrt[n] == c, 
       a Sqrt[1 - n] - b Sqrt[n] == c}, 
      {a, -3, 3}, 
      {b, -3, 3}, 
      {c, -3, 3}]) // Quiet
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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