Taking only the positive sqrt in Mathematica

In summary, to take only the positive square root in Mathematica, you can use the function Sqrt[x], or Power[x, 1/2] for expressions. You can specify which solution you want by using Sqrt[x, n]. To take the positive square root of complex numbers, use Sqrt[x] or Sqrt[x, n]. To simplify square roots and show only the positive solution, use FullSimplify and PowerExpand.
  • #1
Sagekilla
19
0
As my title says, I need to take only the positive square root of some evaluation. For my calculation, the negative square root is extraneous.

What I do is a normalization of a wave function:

Code:
J = Integrate[Psi[x]^2, {x, 0, a}]
sol = Solve[J == 1, A]
A /. sol
My only problem is those above expression will give me A = {-1/sqrt(2), 1/sqrt(2)}.

How can I force Mathematica to only give me positive square root?
 
Physics news on Phys.org
  • #2
Code:
DeleteCases[A,x_/;x<0]

This will ofc only work with expressions mathematica can evaluate numerically or knows to be positive or negative.
 

1. How do I take only the positive square root in Mathematica?

To take only the positive square root in Mathematica, you can use the function Sqrt[x], which will return the positive square root of the number x. If you want to take only the positive square root of an expression, you can use the function Power[x, 1/2], which will return the positive square root of the expression x.

2. Can I specify which solution I want when taking the square root in Mathematica?

Yes, you can specify which solution you want when taking the square root in Mathematica. To do so, you can use the function Sqrt[x, n], where x is the number or expression you want to take the square root of, and n is the solution you want. For example, Sqrt[9, 2] will return the second (positive) solution of the square root of 9, which is 3.

3. What if I only want to take the positive square root of certain numbers in a list?

If you have a list of numbers and you only want to take the positive square root of some of them, you can use the function Sqrt[x, n] in combination with the function Map. For example, if you have a list {-4, 9, -16, 25, -36} and you only want to take the positive square root of the even-indexed numbers, you can use Map[Sqrt[#, 2]&, {2, 4}], which will return {3, 5}.

4. How do I take the positive square root of complex numbers in Mathematica?

To take the positive square root of complex numbers in Mathematica, you can use the function Sqrt[x], where x is the complex number. Mathematica will automatically take the principal (positive) square root of the complex number. You can also specify which solution you want by using the function Sqrt[x, n] as mentioned in question 2.

5. Is there a way to simplify square roots in Mathematica to only show the positive solution?

Yes, there is a way to simplify square roots in Mathematica to only show the positive solution. You can use the function FullSimplify in combination with the function PowerExpand. For example, FullSimplify[PowerExpand[Sqrt[x^2]]] will return x. This will work for both numbers and expressions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
216
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
904
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
823
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top